From f5510afef09a14024923bc920863c8c723fe76e4 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sat, 31 Jul 2021 15:59:52 +0530 Subject: [PATCH] [FormatSort] Fix bug for audio with unknown codec --- yt_dlp/YoutubeDL.py | 1 + yt_dlp/extractor/common.py | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 697b089a14..5b1ee8ee4b 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -1756,6 +1756,7 @@ class YoutubeDL(object): if not allow_multiple_streams[aud_vid] and fmt_info.get(aud_vid[0] + 'codec') != 'none': if get_no_more[aud_vid]: formats_info.pop(i) + break get_no_more[aud_vid] = True if len(formats_info) == 1: diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.py index e892ff3cbc..e767d75b53 100644 --- a/yt_dlp/extractor/common.py +++ b/yt_dlp/extractor/common.py @@ -1497,7 +1497,7 @@ class InfoExtractor(object): 'order': ('m4a', 'aac', 'mp3', 'ogg', 'opus', 'webm', '', 'none'), 'order_free': ('opus', 'ogg', 'webm', 'm4a', 'mp3', 'aac', '', 'none')}, 'hidden': {'visible': False, 'forced': True, 'type': 'extractor', 'max': -1000}, - 'aud_or_vid': {'visible': False, 'forced': True, 'type': 'multiple', 'default': 1, + 'aud_or_vid': {'visible': False, 'forced': True, 'type': 'multiple', 'field': ('vcodec', 'acodec'), 'function': lambda it: int(any(v != 'none' for v in it))}, 'ie_pref': {'priority': True, 'type': 'extractor'}, @@ -1521,7 +1521,8 @@ class InfoExtractor(object): 'br': {'type': 'combined', 'field': ('tbr', 'vbr', 'abr'), 'same_limit': True}, 'size': {'type': 'combined', 'same_limit': True, 'field': ('filesize', 'fs_approx')}, 'ext': {'type': 'combined', 'field': ('vext', 'aext')}, - 'res': {'type': 'multiple', 'field': ('height', 'width'), 'function': min}, + 'res': {'type': 'multiple', 'field': ('height', 'width'), + 'function': lambda it: (lambda l: min(l) if l else 0)(tuple(filter(None, it)))}, # Most of these exist only for compatibility reasons 'dimension': {'type': 'alias', 'field': 'res'}, @@ -1565,7 +1566,7 @@ class InfoExtractor(object): elif key == 'convert': default = 'order' if type == 'ordered' else 'float_string' if field else 'ignore' else: - default = {'type': 'field', 'visible': True, 'order': [], 'not_in_list': (None,), 'function': max}.get(key, None) + default = {'type': 'field', 'visible': True, 'order': [], 'not_in_list': (None,)}.get(key, None) propObj[key] = default return propObj[key] @@ -1705,11 +1706,7 @@ class InfoExtractor(object): type = 'field' # Only 'field' is allowed in multiple for now actual_fields = self._get_field_setting(field, 'field') - def wrapped_function(values): - values = tuple(filter(lambda x: x is not None, values)) - return self._get_field_setting(field, 'function')(values) if values else None - - value = wrapped_function((get_value(f) for f in actual_fields)) + value = self._get_field_setting(field, 'function')(get_value(f) for f in actual_fields) else: value = get_value(field) return self._calculate_field_preference_from_value(format, field, type, value)