From 3a3b57cc2389c5fed6fe1a7694bbcc1bce6c0cb9 Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Sat, 23 May 2020 19:58:25 -0700 Subject: [PATCH] First pass at smallestvideo/smallestaudio filters --- README.md | 2 ++ youtube_dl/YoutubeDL.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 45326c69e..73bad7f6d 100644 --- a/README.md +++ b/README.md @@ -647,8 +647,10 @@ You can also use special names to select particular edge case formats: - `worst`: Select the worst quality format represented by a single file with video and audio. - `bestvideo`: Select the best quality video-only format (e.g. DASH video). May not be available. - `worstvideo`: Select the worst quality video-only format. May not be available. + - `smallestvideo`: Select the smallest video-only format. May not be available. - `bestaudio`: Select the best quality audio only-format. May not be available. - `worstaudio`: Select the worst quality audio only-format. May not be available. + - `smallestaudio`: Select the smallest audio-only format. May not be available. For example, to download the worst quality video-only format you can use `-f worstvideo`. diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 19370f62b..a965a23be 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1283,6 +1283,13 @@ class YoutubeDL(object): if f.get('vcodec') == 'none'] if audio_formats: yield audio_formats[0] + elif format_spec == 'smallestaudio': + video_formats = [ + f for f in formats + if f.get('vcodec') == 'none'] + audio_formats = sorted(audio_formats, key=lambda format: format['filesize']) + if audio_formats: + yield audio_formats[0] elif format_spec == 'bestvideo': video_formats = [ f for f in formats @@ -1295,6 +1302,13 @@ class YoutubeDL(object): if f.get('acodec') == 'none'] if video_formats: yield video_formats[0] + elif format_spec == 'smallestvideo': + video_formats = [ + f for f in formats + if f.get('acodec') == 'none'] + video_formats = sorted(video_formats, key=lambda format: format['filesize']) + if video_formats: + yield video_formats[0] else: extensions = ['mp4', 'flv', 'webm', '3gp', 'm4a', 'mp3', 'ogg', 'aac', 'wav'] if format_spec in extensions: