🏗 Wrap CLI code in main()
Idiomatic `__main__` usage to ease (future) tests and code structure see: https://docs.python.org/3/library/__main__.html#idiomatic-usage
This commit is contained in:
parent
e98417e4e9
commit
e7668fafe1
42
delarte.py
42
delarte.py
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
# coding:utf-8
|
||||
# coding: utf8
|
||||
|
||||
"""delarte.
|
||||
|
||||
|
@ -88,29 +88,43 @@ def write_subtitles(m3u8_url, base_name):
|
|||
return f.name
|
||||
|
||||
|
||||
# command line arguments
|
||||
(UI_LANG, _, STREAM_ID, SLUG) = urlparse(sys.argv[1]).path[1:-1].split("/")
|
||||
VERSION = " ".join(sys.argv[2:])
|
||||
def main():
|
||||
"""CLI function, options passed as arguments."""
|
||||
(UI_LANG, _, STREAM_ID, SLUG) = urlparse(sys.argv[1]).path[1:-1].split("/")
|
||||
VERSION = " ".join(sys.argv[2:])
|
||||
|
||||
if UI_LANG not in ("fr", "de", "en", "es", "pl", "it") or _ != "videos":
|
||||
if UI_LANG not in ("fr", "de", "en", "es", "pl", "it") or _ != "videos":
|
||||
raise ValueError("Invalid URL")
|
||||
|
||||
TITLE, VERSIONS = call_api(
|
||||
TITLE, VERSIONS = call_api(
|
||||
f"https://api.arte.tv/api/player/v2/config/{UI_LANG}/{STREAM_ID}"
|
||||
)
|
||||
)
|
||||
|
||||
FILENAME = TITLE.replace("/", "-")
|
||||
FILENAME = TITLE.replace("/", "-")
|
||||
|
||||
if VERSION not in VERSIONS:
|
||||
if VERSION not in VERSIONS:
|
||||
print(TITLE)
|
||||
for v, (_, l) in VERSIONS.items():
|
||||
print(f"\t{v} : {l}")
|
||||
exit(1)
|
||||
|
||||
M3U8_URL, VERSION_NAME = VERSIONS[VERSION]
|
||||
M3U8_URL, VERSION_NAME = VERSIONS[VERSION]
|
||||
|
||||
write_subtitles(M3U8_URL, FILENAME)
|
||||
write_subtitles(M3U8_URL, FILENAME)
|
||||
|
||||
subprocess.run(
|
||||
[FFMPEG, "-i", M3U8_URL, "-c", "copy", "-bsf:a", "aac_adtstoasc", f"{FILENAME}.mp4"]
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
FFMPEG,
|
||||
"-i",
|
||||
M3U8_URL,
|
||||
"-c",
|
||||
"copy",
|
||||
"-bsf:a",
|
||||
"aac_adtstoasc",
|
||||
f"{FILENAME}.mp4",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
Loading…
Reference in New Issue
Block a user