Add --flat-playlist option (Closes #4003)
authorPhilipp Hagemeister <phihag@phihag.de>
Fri, 24 Oct 2014 12:48:12 +0000 (14:48 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Fri, 24 Oct 2014 12:48:12 +0000 (14:48 +0200)
youtube_dl/YoutubeDL.py
youtube_dl/__init__.py
youtube_dl/options.py

index dec0e20e7907d9fcf0110d6c992f14456336580d..623f9d6fe1cdf98e5a192168ecdef36ab1c4c136 100755 (executable)
@@ -165,6 +165,8 @@ class YoutubeDL(object):
                        'auto' for elaborate guessing
     encoding:          Use this encoding instead of the system-specified.
     extract_flat:      Do not resolve URLs, return the immediate result.
+                       Pass in 'in_playlist' to only show this behavior for
+                       playlist items.
 
     The following parameters are not used by YoutubeDL itself, they are used by
     the FileDownloader:
@@ -568,8 +570,13 @@ class YoutubeDL(object):
 
         result_type = ie_result.get('_type', 'video')
 
-        if self.params.get('extract_flat', False):
-            if result_type in ('url', 'url_transparent'):
+        if result_type in ('url', 'url_transparent'):
+            extract_flat = self.params.get('extract_flat', False)
+            if ((extract_flat == 'in_playlist' and 'playlist' in extra_info) or
+                    extract_flat is True):
+                self.add_extra_info(ie_result, extra_info)
+                if self.params.get('forcejson', False):
+                    self.to_stdout(json.dumps(ie_result))
                 return ie_result
 
         if result_type == 'video':
index a53f6a6219ffe6dd2878d742bba5c0156936affc..c4e1d32db1825dcd1f539344828d2cfde9aecb9e 100644 (file)
@@ -367,6 +367,7 @@ def _real_main(argv=None):
         'youtube_include_dash_manifest': opts.youtube_include_dash_manifest,
         'encoding': opts.encoding,
         'exec_cmd': opts.exec_cmd,
+        'extract_flat': opts.extract_flat,
     }
 
     with YoutubeDL(ydl_opts) as ydl:
index 649361bde3a9eee3bd1222393b069ffb8ac0976d..2b1cd7438669584ea79512e6def4f2272419f004 100644 (file)
@@ -159,6 +159,11 @@ def parseOpts(overrideArguments=None):
         '--ignore-config',
         action='store_true',
         help='Do not read configuration files. When given in the global configuration file /etc/youtube-dl.conf: do not read the user configuration in ~/.config/youtube-dl.conf (%APPDATA%/youtube-dl/config.txt on Windows)')
+    general.add_option(
+        '--flat-playlist',
+        action='store_const', dest='extract_flat', const='in_playlist',
+        default=False,
+        help='Do not extract the videos of a playlist, only list them.')
 
     selection = optparse.OptionGroup(parser, 'Video Selection')
     selection.add_option(