Skip to content

Commit

Permalink
added from master url option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu1845 committed Oct 9, 2021
1 parent 641440f commit 5b9ae77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ python twspace_dl/main.py space_id
## Features
Here's the output of the help option
```
usage: main.py [-h] [-v] [-m] [-w] [-u] [-s] [-k] SPACE_ID
usage: main.py [-h] [-i SPACE_ID] [-f URL] [-v] [-m] [-w] [-u] [-s] [-k]
Script designed to help download twitter spaces
positional arguments:
SPACE_ID
optional arguments:
-h, --help show this help message and exit
-i SPACE_ID, --space-id SPACE_ID
-f URL, --from-url URL
use the master url for the processes(useful for ended spaces)
-v, --verbose
-m, --write-metadata
-w, --write-playlist write the m3u8 used to download the stream
-u, --url display the final url
-u, --url display the master url
-s, --skip-download
-k, --keep-files
```
21 changes: 15 additions & 6 deletions twspace_dl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def merge(self) -> None:
f"{self.title}-{self.id}-tmp.aac",
"-c",
"copy",
f"{self.title}-{self.id}.aac",
f"./{self.title}-{self.id}.aac",
]
subprocess.run(command, check=True)
logging.info("finished merging")
Expand Down Expand Up @@ -167,7 +167,14 @@ def download(self) -> None:
parser = argparse.ArgumentParser(
description="Script designed to help download twitter spaces"
)
parser.add_argument("space_id", type=str, metavar="SPACE_ID")
parser.add_argument("-i", "--space-id", type=str, metavar="SPACE_ID")
parser.add_argument(
"-f",
"--from-url",
type=str,
metavar="URL",
help="use the master url for the processes(useful for ended spaces)",
)
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("-m", "--write-metadata", action="store_true")
parser.add_argument(
Expand All @@ -177,25 +184,27 @@ def download(self) -> None:
help="write the m3u8 used to download the stream",
)
parser.add_argument(
"-u", "--url", action="store_true", help="display the final url"
"-u", "--url", action="store_true", help="display the master url"
)
parser.add_argument("-s", "--skip-download", action="store_true")
parser.add_argument("-k", "--keep-files", action="store_true")
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
if not args.space_id:
print("ID is required")
if not args.space_id and not args.from_url:
print("Either space id or final url should be provided")
sys.exit(1)

logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

twspace_dl = TwspaceDL(args.space_id)
if args.from_url:
twspace_dl.master_url = args.from_url
if args.write_metadata:
twspace_dl.write_metadata()
if args.url:
print(twspace_dl.playlist_url)
print(twspace_dl.master_url)
if args.write_playlist:
twspace_dl.write_playlist()
if not args.skip_download:
Expand Down

0 comments on commit 5b9ae77

Please sign in to comment.