From d3fc8074a4de0ceca369d4c22c7f2fe88e9d983a Mon Sep 17 00:00:00 2001 From: pukkandan Date: Tue, 18 May 2021 01:11:57 +0530 Subject: [PATCH] [youtube] Sort audio-only formats correctly Closes #317 --- yt_dlp/extractor/youtube.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 4ffb90cb9..5e836f883 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -1994,7 +1994,10 @@ def feed_entry(name): formats, itags, stream_ids = [], [], [] itag_qualities = {} player_url = None - q = qualities(['tiny', 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres']) + q = qualities([ + 'tiny', 'audio_quality_low', 'audio_quality_medium', 'audio_quality_high', # Audio only formats + 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres' + ]) streaming_data = player_response.get('streamingData') or {} streaming_formats = streaming_data.get('formats') or [] @@ -2013,6 +2016,8 @@ def feed_entry(name): continue quality = fmt.get('quality') + if quality == 'tiny' or not quality: + quality = fmt.get('audioQuality', '').lower() or quality if itag and quality: itag_qualities[itag] = quality # FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment @@ -2102,9 +2107,6 @@ def feed_entry(name): if itag in itags: continue if itag in itag_qualities: - # Not actually usefull since the sorting is already done with "quality,res,fps,codec" - # but kept to maintain feature parity (and code similarity) with youtube-dl - # Remove if this causes any issues with sorting in future f['quality'] = q(itag_qualities[itag]) filesize = int_or_none(self._search_regex( r'/clen/(\d+)', f.get('fragment_base_url')