Compare commits

...

2 Commits

Author SHA1 Message Date
Andrei Lebedev
81eb5d95b0
Merge 6425e15ea1 into 0153b387e5 2024-06-14 11:07:33 +00:00
Andrei Lebedev
6425e15ea1 [YoutubeDL] Prevent failure on non-audio-video formats 2022-08-09 23:13:47 +02:00
2 changed files with 16 additions and 4 deletions

View File

@ -475,6 +475,18 @@ class TestFormatSelection(unittest.TestCase):
ydl.process_ie_result(info_dict.copy()) ydl.process_ie_result(info_dict.copy())
self.assertEqual(ydl.downloaded_info_dicts[0]['format_id'], 'video+audio') self.assertEqual(ydl.downloaded_info_dicts[0]['format_id'], 'video+audio')
def test_format_selection_non_audio_video(self):
formats = [
{'format_id': 'audio', 'url': TEST_URL, 'ext': 'm4a', 'vcodec': 'none'},
{'format_id': 'chapter', 'ext': 'mhtml', 'acodec': 'none', 'vcodec': 'none', 'url': 'about:invalid'},
{'format_id': 'video', 'url': TEST_URL, 'ext': 'mp4', 'acodec': 'none'},
]
info_dict = _make_result(formats)
ydl = YDL({'format': 'bestvideo+bestaudio'})
ydl.process_ie_result(info_dict.copy())
self.assertEqual(ydl.downloaded_info_dicts[0]['format_id'], 'video+audio')
def test_invalid_format_specs(self): def test_invalid_format_specs(self):
def assert_syntax_error(format_spec): def assert_syntax_error(format_spec):
ydl = YDL({'format': format_spec}) ydl = YDL({'format': format_spec})

View File

@ -1441,25 +1441,25 @@ class YoutubeDL(object):
elif format_spec == 'bestaudio': elif format_spec == 'bestaudio':
audio_formats = [ audio_formats = [
f for f in formats f for f in formats
if f.get('vcodec') == 'none'] if f.get('vcodec') == 'none' and f.get('acodec') != 'none']
if audio_formats: if audio_formats:
yield audio_formats[-1] yield audio_formats[-1]
elif format_spec == 'worstaudio': elif format_spec == 'worstaudio':
audio_formats = [ audio_formats = [
f for f in formats f for f in formats
if f.get('vcodec') == 'none'] if f.get('vcodec') == 'none' and f.get('acodec') != 'none']
if audio_formats: if audio_formats:
yield audio_formats[0] yield audio_formats[0]
elif format_spec == 'bestvideo': elif format_spec == 'bestvideo':
video_formats = [ video_formats = [
f for f in formats f for f in formats
if f.get('acodec') == 'none'] if f.get('acodec') == 'none' and f.get('vcodec') != 'none']
if video_formats: if video_formats:
yield video_formats[-1] yield video_formats[-1]
elif format_spec == 'worstvideo': elif format_spec == 'worstvideo':
video_formats = [ video_formats = [
f for f in formats f for f in formats
if f.get('acodec') == 'none'] if f.get('acodec') == 'none' and f.get('vcodec') != 'none']
if video_formats: if video_formats:
yield video_formats[0] yield video_formats[0]
else: else: