[youtube] Prefer audio stream that YouTube considers default

Fixes: https://github.com/ytdl-org/youtube-dl/issues/29864
Related: https://github.com/clsid2/mpc-hc/issues/1268
This commit is contained in:
pukkandan 2021-08-26 07:40:02 +05:30
parent 198e3a04c9
commit 26e8e04454
No known key found for this signature in database
GPG key ID: 0F00D95A001F4698

View file

@ -2622,7 +2622,8 @@ def _extract_formats(self, streaming_data, video_id, player_url, is_live):
'filesize': int_or_none(fmt.get('contentLength')),
'format_id': itag,
'format_note': ', '.join(filter(None, (
audio_track.get('displayName'),
'%s%s' % (audio_track.get('displayName') or '',
' (default)' if audio_track.get('audioIsDefault') else ''),
fmt.get('qualityLabel') or quality.replace('audio_quality_', '')))),
'fps': int_or_none(fmt.get('fps')),
'height': height,
@ -2631,6 +2632,7 @@ def _extract_formats(self, streaming_data, video_id, player_url, is_live):
'url': fmt_url,
'width': int_or_none(fmt.get('width')),
'language': audio_track.get('id', '').split('.')[0],
'language_preference': 1 if audio_track.get('audioIsDefault') else -1,
}
mime_mobj = re.match(
r'((?:[^/]+)/(?:[^;]+))(?:;\s*codecs="([^"]+)")?', fmt.get('mimeType') or '')
@ -2817,7 +2819,7 @@ def feed_entry(name):
# Source is given priority since formats that throttle are given lower source_preference
# When throttling issue is fully fixed, remove this
self._sort_formats(formats, ('quality', 'height', 'fps', 'source'))
self._sort_formats(formats, ('quality', 'res', 'fps', 'source', 'codec:vp9.2', 'size', 'br', 'lang'))
keywords = get_first(video_details, 'keywords', expected_type=list) or []
if not keywords and webpage: