diff options
author | asuyou <asuyou@users.noreply.github.com> | 2021-11-19 20:37:55 +0000 |
---|---|---|
committer | asuyou <asuyou@users.noreply.github.com> | 2021-11-19 20:37:55 +0000 |
commit | 69746826f8765dc61c2b4ba82bc4ccbe664bc933 (patch) | |
tree | 0677647a25bf1f146615ec3b81c6b6bc32cbf999 | |
parent | Audio quality sorting now follows mp4 (diff) | |
download | metube-69746826f8765dc61c2b4ba82bc4ccbe664bc933.tar.gz metube-69746826f8765dc61c2b4ba82bc4ccbe664bc933.tar.bz2 metube-69746826f8765dc61c2b4ba82bc4ccbe664bc933.zip |
dl_formats options are now inline
-rw-r--r-- | app/dl_formats.py | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/app/dl_formats.py b/app/dl_formats.py index b47ae5c..d0af344 100644 --- a/app/dl_formats.py +++ b/app/dl_formats.py @@ -49,27 +49,6 @@ def get_opts(format: str, quality: str, ytdl_opts: dict) -> dict: return ytdl_opts -def _get_audio_fmt(quality: str) -> str: - if quality == "best" or quality in ("128", "192", "320"): - audio_fmt = "bestaudio/best" - # Audio quality needs to be set post-download, set in opts - else: - raise Exception(f"Unknown quality {quality}") - - return audio_fmt - - -def _get_video_res(quality: str) -> str: - if quality in ("best", "audio"): - video_fmt = "" - elif quality in ("1440", "1080", "720", "480"): - video_fmt = f"[height<={quality}]" - else: - raise Exception(f"Unknown quality {quality}") - - return video_fmt - - def _get_final_fmt(format: str, quality: str) -> str: vfmt, afmt, vres = "", "", "" @@ -81,11 +60,20 @@ def _get_final_fmt(format: str, quality: str) -> str: if quality == "audio": final_fmt = "bestaudio/best" else: - vres = _get_video_res(quality) + if quality in ("best", "audio"): + vres = "" + elif quality in ("1440", "1080", "720", "480"): + vres = f"[height<={quality}]" + else: + raise Exception(f"Unknown quality {quality}") combo = vres + vfmt final_fmt = f"bestvideo{combo}+bestaudio{afmt}/best{combo}" elif format == "mp3": - final_fmt = _get_audio_fmt(quality) + if quality == "best" or quality in ("128", "192", "320"): + final_fmt = "bestaudio/best" + # Audio quality needs to be set post-download, set in opts + else: + raise Exception(f"Unknown quality {quality}") else: raise Exception(f"Unkown format {format}") |