[YoutubeDL] format spec: Do not fail when a filter gives an empty result
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Sat, 4 Jul 2015 19:41:09 +0000 (21:41 +0200)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Sat, 4 Jul 2015 19:41:09 +0000 (21:41 +0200)
For example with 'best[height<40]' we ended getting a 'IndexError: list index out of range'.

test/test_YoutubeDL.py
youtube_dl/YoutubeDL.py

index f103779d37435229e8038471164f12017d0c18a9..bf2baae07fe443b3865ea2b1e4e540b466cff84e 100644 (file)
@@ -15,7 +15,7 @@ from youtube_dl import YoutubeDL
 from youtube_dl.compat import compat_str
 from youtube_dl.extractor import YoutubeIE
 from youtube_dl.postprocessor.common import PostProcessor
-from youtube_dl.utils import match_filter_func
+from youtube_dl.utils import ExtractorError, match_filter_func
 
 TEST_URL = 'http://localhost/sample.mp4'
 
@@ -362,6 +362,13 @@ class TestFormatSelection(unittest.TestCase):
         downloaded_ids = [info['format_id'] for info in ydl.downloaded_info_dicts]
         self.assertEqual(downloaded_ids, ['B', 'C', 'D'])
 
+        ydl = YDL({'format': 'best[height<40]'})
+        try:
+            ydl.process_ie_result(info_dict)
+        except ExtractorError:
+            pass
+        self.assertEqual(ydl.downloaded_info_dicts, [])
+
 
 class TestYoutubeDL(unittest.TestCase):
     def test_subtitles(self):
index 5a79e5f1d16cfc33d136574d2eb7b0b42cdf6142..6478d05dc72ed7d66b1268fe3f01bfce25e8fff7 100755 (executable)
@@ -1005,6 +1005,9 @@ class YoutubeDL(object):
                 format_spec = selector.selector
 
                 def selector_function(formats):
+                    formats = list(formats)
+                    if not formats:
+                        return
                     if format_spec == 'all':
                         for f in formats:
                             yield f