diff --git a/delarte.py b/delarte.py index a3f797e..0bdafd0 100755 --- a/delarte.py +++ b/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": - raise ValueError("Invalid URL") + if UI_LANG not in ("fr", "de", "en", "es", "pl", "it") or _ != "videos": + raise ValueError("Invalid URL") -TITLE, VERSIONS = call_api( - f"https://api.arte.tv/api/player/v2/config/{UI_LANG}/{STREAM_ID}" -) + 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: - print(TITLE) - for v, (_, l) in VERSIONS.items(): - print(f"\t{v} : {l}") - exit(1) + 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())