mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-11-04 08:35:12 +00:00 
			
		
		
		
	[formatsort] Remove unnecessary field_preference from extractors
				
					
				
			These were written with the old format sorting in mind and is no longer needed
This commit is contained in:
		@@ -67,7 +67,7 @@ class AluraIE(InfoExtractor):
 | 
				
			|||||||
                            f['height'] = int('720' if m.group('res') == 'hd' else '480')
 | 
					                            f['height'] = int('720' if m.group('res') == 'hd' else '480')
 | 
				
			||||||
                formats.extend(video_format)
 | 
					                formats.extend(video_format)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self._sort_formats(formats, field_preference=('height', 'width', 'tbr', 'format_id'))
 | 
					            self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return {
 | 
					            return {
 | 
				
			||||||
                'id': video_id,
 | 
					                'id': video_id,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -125,7 +125,7 @@ class AolIE(YahooIE):
 | 
				
			|||||||
                        'height': int_or_none(qs.get('h', [None])[0]),
 | 
					                        'height': int_or_none(qs.get('h', [None])[0]),
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
                formats.append(f)
 | 
					                formats.append(f)
 | 
				
			||||||
        self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            'id': video_id,
 | 
					            'id': video_id,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,8 +72,7 @@ class AparatIE(InfoExtractor):
 | 
				
			|||||||
                            r'(\d+)[pP]', label or '', 'height',
 | 
					                            r'(\d+)[pP]', label or '', 'height',
 | 
				
			||||||
                            default=None)),
 | 
					                            default=None)),
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
        self._sort_formats(
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
            formats, field_preference=('height', 'width', 'tbr', 'format_id'))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        info = self._search_json_ld(webpage, video_id, default={})
 | 
					        info = self._search_json_ld(webpage, video_id, default={})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -152,8 +152,7 @@ class ArcPublishingIE(InfoExtractor):
 | 
				
			|||||||
                    'url': s_url,
 | 
					                    'url': s_url,
 | 
				
			||||||
                    'preference': -1,
 | 
					                    'preference': -1,
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
        self._sort_formats(
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
            formats, ('preference', 'width', 'height', 'vbr', 'filesize', 'tbr', 'ext', 'format_id'))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        subtitles = {}
 | 
					        subtitles = {}
 | 
				
			||||||
        for subtitle in (try_get(video, lambda x: x['subtitles']['urls'], list) or []):
 | 
					        for subtitle in (try_get(video, lambda x: x['subtitles']['urls'], list) or []):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -571,7 +571,7 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
 | 
				
			|||||||
                        'ext': 'flv',
 | 
					                        'ext': 'flv',
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
                    formats.append(format_info)
 | 
					                    formats.append(format_info)
 | 
				
			||||||
        self._sort_formats(formats, ('preference', 'language_preference', 'height', 'width', 'tbr', 'fps'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        metadata = self._call_rpc_api(
 | 
					        metadata = self._call_rpc_api(
 | 
				
			||||||
            'VideoPlayer_GetMediaMetadata', video_id,
 | 
					            'VideoPlayer_GetMediaMetadata', video_id,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -185,7 +185,7 @@ class LeIE(InfoExtractor):
 | 
				
			|||||||
                    f['height'] = int_or_none(format_id[:-1])
 | 
					                    f['height'] = int_or_none(format_id[:-1])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                formats.append(f)
 | 
					                formats.append(f)
 | 
				
			||||||
        self._sort_formats(formats, ('height', 'quality', 'format_id'))
 | 
					        self._sort_formats(formats, ('res', 'quality'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        publish_time = parse_iso8601(self._html_search_regex(
 | 
					        publish_time = parse_iso8601(self._html_search_regex(
 | 
				
			||||||
            r'发布时间 ([^<>]+) ', page, 'publish time', default=None),
 | 
					            r'发布时间 ([^<>]+) ', page, 'publish time', default=None),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -124,7 +124,10 @@ class LinkedInLearningIE(LinkedInLearningBaseIE):
 | 
				
			|||||||
                streaming_url, video_slug, 'mp4',
 | 
					                streaming_url, video_slug, 'mp4',
 | 
				
			||||||
                'm3u8_native', m3u8_id='hls', fatal=False))
 | 
					                'm3u8_native', m3u8_id='hls', fatal=False))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._sort_formats(formats, ('width', 'height', 'source_preference', 'tbr', 'abr'))
 | 
					        # It seems like this would be correctly handled by default
 | 
				
			||||||
 | 
					        # However, unless someone can confirm this, the old
 | 
				
			||||||
 | 
					        # behaviour is being kept as-is
 | 
				
			||||||
 | 
					        self._sort_formats(formats, ('res', 'source_preference'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            'id': self._get_video_id(video_data, course_slug, video_slug),
 | 
					            'id': self._get_video_id(video_data, course_slug, video_slug),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,7 +67,7 @@ class MassengeschmackTVIE(InfoExtractor):
 | 
				
			|||||||
                'vcodec': 'none' if format_id.startswith('Audio') else None,
 | 
					                'vcodec': 'none' if format_id.startswith('Audio') else None,
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._sort_formats(formats, ('width', 'height', 'filesize', 'tbr'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            'id': episode,
 | 
					            'id': episode,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,7 +72,7 @@ class NYTimesBaseIE(InfoExtractor):
 | 
				
			|||||||
                    'tbr': int_or_none(video.get('bitrate'), 1000) or None,
 | 
					                    'tbr': int_or_none(video.get('bitrate'), 1000) or None,
 | 
				
			||||||
                    'ext': ext,
 | 
					                    'ext': ext,
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
        self._sort_formats(formats, ('height', 'width', 'filesize', 'tbr', 'fps', 'format_id'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        thumbnails = []
 | 
					        thumbnails = []
 | 
				
			||||||
        for image in video_data.get('images', []):
 | 
					        for image in video_data.get('images', []):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,8 +54,7 @@ class PinterestBaseIE(InfoExtractor):
 | 
				
			|||||||
                        'height': int_or_none(format_dict.get('height')),
 | 
					                        'height': int_or_none(format_dict.get('height')),
 | 
				
			||||||
                        'duration': duration,
 | 
					                        'duration': duration,
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
            self._sort_formats(
 | 
					            self._sort_formats(formats)
 | 
				
			||||||
                formats, field_preference=('height', 'width', 'tbr', 'format_id'))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        description = data.get('description') or data.get('description_html') or data.get('seo_description')
 | 
					        description = data.get('description') or data.get('description_html') or data.get('seo_description')
 | 
				
			||||||
        timestamp = unified_timestamp(data.get('created_at'))
 | 
					        timestamp = unified_timestamp(data.get('created_at'))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@ class RedditIE(InfoExtractor):
 | 
				
			|||||||
            'https://v.redd.it/%s/DASHPlaylist.mpd' % video_id, video_id,
 | 
					            'https://v.redd.it/%s/DASHPlaylist.mpd' % video_id, video_id,
 | 
				
			||||||
            mpd_id='dash', fatal=False))
 | 
					            mpd_id='dash', fatal=False))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._sort_formats(formats, ('height', 'width'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            'id': video_id,
 | 
					            'id': video_id,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,7 +80,9 @@ class SendtoNewsIE(InfoExtractor):
 | 
				
			|||||||
                    'format_id': '%s-%d' % (determine_protocol(f), tbr),
 | 
					                    'format_id': '%s-%d' % (determine_protocol(f), tbr),
 | 
				
			||||||
                    'tbr': tbr,
 | 
					                    'tbr': tbr,
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
            self._sort_formats(info_dict['formats'], ('tbr', 'height', 'width', 'format_id'))
 | 
					            # 'tbr' was explicitly set to be prefered over 'height' originally,
 | 
				
			||||||
 | 
					            # So this is being kept unless someone can confirm this is unnecessary
 | 
				
			||||||
 | 
					            self._sort_formats(info_dict['formats'], ('tbr', 'res'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            thumbnails = []
 | 
					            thumbnails = []
 | 
				
			||||||
            if video.get('thumbnailUrl'):
 | 
					            if video.get('thumbnailUrl'):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -129,7 +129,7 @@ class SpankBangIE(InfoExtractor):
 | 
				
			|||||||
                    format_url = format_url[0]
 | 
					                    format_url = format_url[0]
 | 
				
			||||||
                extract_format(format_id, format_url)
 | 
					                extract_format(format_id, format_url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'tbr', 'format_id'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        info = self._search_json_ld(webpage, video_id, default={})
 | 
					        info = self._search_json_ld(webpage, video_id, default={})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -108,7 +108,7 @@ class SpankwireIE(InfoExtractor):
 | 
				
			|||||||
            formats.extend(self._extract_m3u8_formats(
 | 
					            formats.extend(self._extract_m3u8_formats(
 | 
				
			||||||
                m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
 | 
					                m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
 | 
				
			||||||
                m3u8_id='hls', fatal=False))
 | 
					                m3u8_id='hls', fatal=False))
 | 
				
			||||||
        self._sort_formats(formats, ('height', 'tbr', 'width', 'format_id'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        view_count = str_to_int(video.get('viewed'))
 | 
					        view_count = str_to_int(video.get('viewed'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -138,7 +138,10 @@ class ThreeQSDNIE(InfoExtractor):
 | 
				
			|||||||
                f['preference'] = -40
 | 
					                f['preference'] = -40
 | 
				
			||||||
            elif f.get('vcodec') == 'none':
 | 
					            elif f.get('vcodec') == 'none':
 | 
				
			||||||
                f['preference'] = -50
 | 
					                f['preference'] = -50
 | 
				
			||||||
        self._sort_formats(formats, ('preference', 'width', 'height', 'source_preference', 'tbr', 'vbr', 'abr', 'ext', 'format_id'))
 | 
					        # It seems like this would be correctly handled by default
 | 
				
			||||||
 | 
					        # However, unless someone can confirm this, the old
 | 
				
			||||||
 | 
					        # behaviour is being kept as-is
 | 
				
			||||||
 | 
					        self._sort_formats(formats, ('res', 'source_preference'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        subtitles = {}
 | 
					        subtitles = {}
 | 
				
			||||||
        for subtitle in (config.get('subtitles') or []):
 | 
					        for subtitle in (config.get('subtitles') or []):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -405,7 +405,7 @@ class UdemyIE(InfoExtractor):
 | 
				
			|||||||
                if f.get('url'):
 | 
					                if f.get('url'):
 | 
				
			||||||
                    formats.append(f)
 | 
					                    formats.append(f)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._sort_formats(formats, field_preference=('height', 'width', 'tbr', 'format_id'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            'id': video_id,
 | 
					            'id': video_id,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,7 +91,7 @@ class UMGDeIE(InfoExtractor):
 | 
				
			|||||||
        if not formats:
 | 
					        if not formats:
 | 
				
			||||||
            for format_id in (867, 836, 940):
 | 
					            for format_id in (867, 836, 940):
 | 
				
			||||||
                add_m3u8_format(format_id)
 | 
					                add_m3u8_format(format_id)
 | 
				
			||||||
        self._sort_formats(formats, ('width', 'height', 'filesize', 'tbr'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            'id': video_id,
 | 
					            'id': video_id,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -134,7 +134,7 @@ class ViewLiftEmbedIE(ViewLiftBaseIE):
 | 
				
			|||||||
        if hls_url:
 | 
					        if hls_url:
 | 
				
			||||||
            formats.extend(self._extract_m3u8_formats(
 | 
					            formats.extend(self._extract_m3u8_formats(
 | 
				
			||||||
                hls_url, film_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
 | 
					                hls_url, film_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
 | 
				
			||||||
        self._sort_formats(formats, ('height', 'tbr', 'format_id'))
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        info = {
 | 
					        info = {
 | 
				
			||||||
            'id': film_id,
 | 
					            'id': film_id,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -116,7 +116,8 @@ class VimeoBaseInfoExtractor(InfoExtractor):
 | 
				
			|||||||
    def _vimeo_sort_formats(self, formats):
 | 
					    def _vimeo_sort_formats(self, formats):
 | 
				
			||||||
        # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
 | 
					        # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
 | 
				
			||||||
        # at the same time without actual units specified. This lead to wrong sorting.
 | 
					        # at the same time without actual units specified. This lead to wrong sorting.
 | 
				
			||||||
        self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'tbr', 'format_id'))
 | 
					        # But since yt-dlp prefers 'res,fps' anyway, 'field_preference' is not needed
 | 
				
			||||||
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _parse_config(self, config, video_id):
 | 
					    def _parse_config(self, config, video_id):
 | 
				
			||||||
        video_data = config['video']
 | 
					        video_data = config['video']
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -231,7 +231,7 @@ class XHamsterIE(InfoExtractor):
 | 
				
			|||||||
                                        'Referer': standard_url,
 | 
					                                        'Referer': standard_url,
 | 
				
			||||||
                                    },
 | 
					                                    },
 | 
				
			||||||
                                })
 | 
					                                })
 | 
				
			||||||
            self._sort_formats(formats, field_preference=('height', 'width', 'tbr', 'format_id'))
 | 
					            self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            categories_list = video.get('categories')
 | 
					            categories_list = video.get('categories')
 | 
				
			||||||
            if isinstance(categories_list, list):
 | 
					            if isinstance(categories_list, list):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user