aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/postprocessor/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp/postprocessor/common.py')
-rw-r--r--yt_dlp/postprocessor/common.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/yt_dlp/postprocessor/common.py b/yt_dlp/postprocessor/common.py
index b6d06f33f..9bd025ff6 100644
--- a/yt_dlp/postprocessor/common.py
+++ b/yt_dlp/postprocessor/common.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
+import functools
import os
from ..compat import compat_str
@@ -67,6 +68,25 @@ class PostProcessor(object):
"""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.