diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-02-13 01:34:27 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-02-13 01:35:54 +0530 |
commit | c154302c588c3d4362cec4fc5545e7e5d2bcf7a3 (patch) | |
tree | cf3cd80fc7611bd0993b332899600ba0f82947f3 | |
parent | 5712943b764ba819ef479524c32700228603817a (diff) | |
download | hypervideo-pre-c154302c588c3d4362cec4fc5545e7e5d2bcf7a3.tar.lz hypervideo-pre-c154302c588c3d4362cec4fc5545e7e5d2bcf7a3.tar.xz hypervideo-pre-c154302c588c3d4362cec4fc5545e7e5d2bcf7a3.zip |
Bugfix for 39f32f1715c0dffb7626dda7307db6388bb7abaa
-rw-r--r-- | yt_dlp/YoutubeDL.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 4b652d172..d214a6449 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -2466,15 +2466,8 @@ class YoutubeDL: def sort_formats(self, info_dict): formats = self._get_formats(info_dict) - if not formats: - return - # Backward compatibility with InfoExtractor._sort_formats - field_preference = formats[0].pop('__sort_fields', None) - if field_preference: - info_dict['_format_sort_fields'] = field_preference - formats.sort(key=FormatSorter( - self, info_dict.get('_format_sort_fields', [])).calculate_preference) + self, info_dict.get('_format_sort_fields') or []).calculate_preference) def process_video_result(self, info_dict, download=True): assert info_dict.get('_type', 'video') == 'video' @@ -2563,6 +2556,11 @@ class YoutubeDL: formats = self._get_formats(info_dict) + # Backward compatibility with InfoExtractor._sort_formats + field_preference = formats[0].pop('__sort_fields', None) + if field_preference: + info_dict['_format_sort_fields'] = field_preference + # or None ensures --clean-infojson removes it info_dict['_has_drm'] = any(f.get('has_drm') for f in formats) or None if not self.params.get('allow_unplayable_formats'): @@ -2623,7 +2621,10 @@ class YoutubeDL: if '__x_forwarded_for_ip' in info_dict: del info_dict['__x_forwarded_for_ip'] - self.sort_formats({'formats': formats}) + self.sort_formats({ + 'formats': formats, + '_format_sort_fields': info_dict.get('_format_sort_fields') + }) # Sanitize and group by format_id formats_dict = {} |