diff options
author | asuyou <asuyou@users.noreply.github.com> | 2021-11-05 23:46:40 +0000 |
---|---|---|
committer | asuyou <asuyou@users.noreply.github.com> | 2021-11-05 23:46:40 +0000 |
commit | 63ec5c37afc99453125b855559c8913811217bdf (patch) | |
tree | 994be43bc11dbdd5ff9faaf49685acdc066786fa /app | |
parent | Any now shows all avaliable formats (diff) | |
download | metube-63ec5c37afc99453125b855559c8913811217bdf.tar.gz metube-63ec5c37afc99453125b855559c8913811217bdf.tar.bz2 metube-63ec5c37afc99453125b855559c8913811217bdf.zip |
Changed back to original format download
Diffstat (limited to 'app')
-rw-r--r-- | app/dl_formats.py | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/app/dl_formats.py b/app/dl_formats.py index f1b3881..84be68e 100644 --- a/app/dl_formats.py +++ b/app/dl_formats.py @@ -12,24 +12,12 @@ def get_format(format: str, quality: str) -> str: Returns: dl_format: Formatted download string """ - audio_fmt = "" - video_fmt = "" final_fmt = "" if format.startswith("custom:"): final_fmt = format[7:] - elif format == "any": - final_fmt = "bv*+ba/b" - elif format == "mp3": - audio_fmt = _get_audio_fmt(quality) - elif format == "mp4": - audio_fmt = "ba/b" - video_fmt = _get_video_fmt(quality) else: - raise Exception(f"Unknown format {format}") - - if not final_fmt: - final_fmt = video_fmt + audio_fmt + final_fmt = _get_final_fmt(format, quality) return final_fmt @@ -58,15 +46,12 @@ def get_opts(format: str, quality: str, ytdl_opts: dict) -> dict: {"key": "FFmpegExtractAudio", "preferredcodec": "mp3", **extra_args}, ) - elif format == "mp4": - ytdl_opts["merge_output_format"] = "mp4" - return ytdl_opts def _get_audio_fmt(quality: str) -> str: if quality == "best" or quality in ("128", "192", "320"): - audio_fmt = "ba/b" + audio_fmt = "bestaudio/best" # Audio quality needs to be set post-download, set in opts else: raise Exception(f"Unknown quality {quality}") @@ -74,12 +59,29 @@ def _get_audio_fmt(quality: str) -> str: return audio_fmt -def _get_video_fmt(quality: str) -> str: +def _get_video_res(quality: str) -> str: if quality == "best": - video_fmt = "bv*+" + video_fmt = "" elif quality in ("1440", "1080", "720", "480"): - video_fmt = f"bv[height<={quality}]+" + 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 = "", "", "" + + if format == "mp4": + # video {res} {vfmt} + audio {afmt} {res} {vfmt} + vfmt, afmt = "[ext=mp4]", "[ext=m4a]" + vres = _get_video_res(quality) + combo = vres + vfmt + final_fmt = f"bestvideo{combo}+bestaudio{afmt}/best{combo}" + elif format == "mp3": + final_fmt = _get_audio_fmt(quality) + else: + raise Exception(f"Unkown format {format}") + + return final_fmt |