🏗 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:
freezed 2022-12-06 01:22:07 +01:00
parent e98417e4e9
commit e7668fafe1

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3
# coding:utf-8
# coding: utf8
"""delarte.
@ -88,7 +88,8 @@ def write_subtitles(m3u8_url, base_name):
return f.name
# command line arguments
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:])
@ -112,5 +113,18 @@ M3U8_URL, VERSION_NAME = VERSIONS[VERSION]
write_subtitles(M3U8_URL, FILENAME)
subprocess.run(
[FFMPEG, "-i", M3U8_URL, "-c", "copy", "-bsf:a", "aac_adtstoasc", f"{FILENAME}.mp4"]
[
FFMPEG,
"-i",
M3U8_URL,
"-c",
"copy",
"-bsf:a",
"aac_adtstoasc",
f"{FILENAME}.mp4",
]
)
if __name__ == "__main__":
sys.exit(main())