[youtube] Sort audio-only formats correctly

Closes #317
This commit is contained in:
pukkandan 2021-05-18 01:11:57 +05:30
parent 9c2b75b561
commit d3fc8074a4
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698

View File

@ -1994,7 +1994,10 @@ def feed_entry(name):
formats, itags, stream_ids = [], [], [] formats, itags, stream_ids = [], [], []
itag_qualities = {} itag_qualities = {}
player_url = None 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_data = player_response.get('streamingData') or {}
streaming_formats = streaming_data.get('formats') or [] streaming_formats = streaming_data.get('formats') or []
@ -2013,6 +2016,8 @@ def feed_entry(name):
continue continue
quality = fmt.get('quality') quality = fmt.get('quality')
if quality == 'tiny' or not quality:
quality = fmt.get('audioQuality', '').lower() or quality
if itag and quality: if itag and quality:
itag_qualities[itag] = quality itag_qualities[itag] = quality
# FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment # FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment
@ -2102,9 +2107,6 @@ def feed_entry(name):
if itag in itags: if itag in itags:
continue continue
if itag in itag_qualities: 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]) f['quality'] = q(itag_qualities[itag])
filesize = int_or_none(self._search_regex( filesize = int_or_none(self._search_regex(
r'/clen/(\d+)', f.get('fragment_base_url') r'/clen/(\d+)', f.get('fragment_base_url')