[YoutubeDL] format spec: treat 'all' like a normal specifier
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Sun, 28 Jun 2015 20:48:02 +0000 (22:48 +0200)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Sun, 28 Jun 2015 20:48:02 +0000 (22:48 +0200)
So you can use filters with it, for example 'all[width>=400][width<=600]'.

test/test_YoutubeDL.py
youtube_dl/YoutubeDL.py

index 8f7aef512789efd7f779aa46960bfefb363a36fc..709e3100f0a6fbe315ea92344d569c4fc64cf47d 100644 (file)
@@ -317,6 +317,11 @@ class TestFormatSelection(unittest.TestCase):
         downloaded = ydl.downloaded_info_dicts[0]
         self.assertEqual(downloaded['format_id'], 'G')
 
+        ydl = YDL({'format': 'all[width>=400][width<=600]'})
+        ydl.process_ie_result(info_dict)
+        downloaded_ids = [info['format_id'] for info in ydl.downloaded_info_dicts]
+        self.assertEqual(downloaded_ids, ['B', 'C', 'D'])
+
 
 class TestYoutubeDL(unittest.TestCase):
     def test_subtitles(self):
index 17a5407b983fbadc00453d081ccd567f10f3dade..258e612afa5540ebefe4189d91d029768672f0ae 100755 (executable)
@@ -990,7 +990,10 @@ class YoutubeDL(object):
                 format_spec = selector.selector
 
                 def selector_function(formats):
-                    if format_spec in ['best', 'worst', None]:
+                    if format_spec == 'all':
+                        for f in formats:
+                            yield f
+                    elif format_spec in ['best', 'worst', None]:
                         format_idx = 0 if format_spec == 'worst' else -1
                         audiovideo_formats = [
                             f for f in formats
@@ -1226,12 +1229,8 @@ class YoutubeDL(object):
                     req_format_list.append('bestvideo+bestaudio')
             req_format_list.append('best')
             req_format = '/'.join(req_format_list)
-        formats_to_download = []
-        if req_format == 'all':
-            formats_to_download = formats
-        else:
-            format_selector = self.build_format_selector(req_format)
-            formats_to_download = list(format_selector(formats))
+        format_selector = self.build_format_selector(req_format)
+        formats_to_download = list(format_selector(formats))
         if not formats_to_download:
             raise ExtractorError('requested format not available',
                                  expected=True)