]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/postprocessor/common.py
Allow `images` formats
[yt-dlp.git] / yt_dlp / postprocessor / common.py
index f8f4e7693f2175700a63ef9a0e3187b15bcdc869..9bd025ff6ce5745005d1bb1c018ebdfc2d62b6f8 100644 (file)
@@ -1,5 +1,6 @@
 from __future__ import unicode_literals
 
+import functools
 import os
 
 from ..compat import compat_str
@@ -54,10 +55,9 @@ def report_error(self, text, *args, **kwargs):
         if self._downloader:
             return self._downloader.report_error(text, *args, **kwargs)
 
-    def write_debug(self, text, prefix=True, *args, **kwargs):
-        tag = '[debug] ' if prefix else ''
-        if self.get_param('verbose', False) and self._downloader:
-            return self._downloader.to_screen('%s%s' % (tag, text), *args, **kwargs)
+    def write_debug(self, text, *args, **kwargs):
+        if self._downloader:
+            return self._downloader.write_debug(text, *args, **kwargs)
 
     def get_param(self, name, default=None, *args, **kwargs):
         if self._downloader:
@@ -68,6 +68,25 @@ def set_downloader(self, downloader):
         """Sets the downloader for this PP."""
         self._downloader = downloader
 
+    @staticmethod
+    def _restrict_to(*, video=True, audio=True, images=True):
+        allowed = {'video': video, 'audio': audio, 'images': images}
+
+        def decorator(func):
+            @functools.wraps(func)
+            def wrapper(self, info):
+                format_type = (
+                    'video' if info['vcodec'] != 'none'
+                    else 'audio' if info['acodec'] != 'none'
+                    else 'images')
+                if allowed[format_type]:
+                    func(self, info)
+                else:
+                    self.to_screen('Skipping %s' % format_type)
+                    return [], info
+            return wrapper
+        return decorator
+
     def run(self, information):
         """Run the PostProcessor.
 
@@ -91,10 +110,18 @@ def try_utime(self, path, atime, mtime, errnote='Cannot update utime of file'):
         except Exception:
             self.report_warning(errnote)
 
-    def _configuration_args(self, *args, **kwargs):
+    def _configuration_args(self, exe, keys=None, default=[], use_compat=True):
+        pp_key = self.pp_key().lower()
+        exe = exe.lower()
+        root_key = exe if pp_key == exe else '%s+%s' % (pp_key, exe)
+        keys = ['%s%s' % (root_key, k) for k in (keys or [''])]
+        if root_key in keys:
+            keys += [root_key] + ([] if pp_key == exe else [(self.pp_key(), exe)]) + ['default']
+        else:
+            use_compat = False
         return cli_configuration_args(
-            self._downloader.params.get('postprocessor_args'),
-            self.pp_key().lower(), *args, **kwargs)
+            self.get_param('postprocessor_args'),
+            keys, default, use_compat)
 
 
 class AudioConversionError(PostProcessingError):