aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dlc/postprocessor/common.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan@gmail.com>2021-01-10 19:14:54 +0530
committerpukkandan <pukkandan@gmail.com>2021-01-10 22:22:24 +0530
commitf446cc66675629d3e043800d9ce74d3327f9fdfa (patch)
tree80c00c707c1404d088c1d5ded88248f69567243c /youtube_dlc/postprocessor/common.py
parentebdd9275c3e65b558125381a00fd77b0a8c2ce73 (diff)
downloadhypervideo-pre-f446cc66675629d3e043800d9ce74d3327f9fdfa.tar.lz
hypervideo-pre-f446cc66675629d3e043800d9ce74d3327f9fdfa.tar.xz
hypervideo-pre-f446cc66675629d3e043800d9ce74d3327f9fdfa.zip
Create `to_screen` and similar functions in postprocessor/common
`to_screen`, `report_warning`, `report_error`, `write_debug`, `get_param` This is a first step in standardizing these function. This has to be done eventually for extractors and downloaders too
Diffstat (limited to 'youtube_dlc/postprocessor/common.py')
-rw-r--r--youtube_dlc/postprocessor/common.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/youtube_dlc/postprocessor/common.py b/youtube_dlc/postprocessor/common.py
index 6e84ff592..1a893d05f 100644
--- a/youtube_dlc/postprocessor/common.py
+++ b/youtube_dlc/postprocessor/common.py
@@ -37,7 +37,25 @@ class PostProcessor(object):
self.PP_NAME = self.__class__.__name__[:-2]
def to_screen(self, text, *args, **kwargs):
- return self._downloader.to_screen('[%s] %s' % (self.PP_NAME, text), *args, **kwargs)
+ if self._downloader:
+ return self._downloader.to_screen('[%s] %s' % (self.PP_NAME, text), *args, **kwargs)
+
+ def report_warning(self, text, *args, **kwargs):
+ if self._downloader:
+ return self._downloader.report_warning(text, *args, **kwargs)
+
+ def report_error(self, text, *args, **kwargs):
+ if self._downloader:
+ return self._downloader.report_error(text, *args, **kwargs)
+
+ def write_debug(self, text, *args, **kwargs):
+ if self.get_param('verbose', False):
+ return self._downloader.to_screen('[debug] %s' % text, *args, **kwargs)
+
+ def get_param(self, name, default=None, *args, **kwargs):
+ if self._downloader:
+ return self._downloader.params.get(name, default, *args, **kwargs)
+ return default
def set_downloader(self, downloader):
"""Sets the downloader for this PP."""
@@ -64,10 +82,10 @@ class PostProcessor(object):
try:
os.utime(encodeFilename(path), (atime, mtime))
except Exception:
- self._downloader.report_warning(errnote)
+ self.report_warning(errnote)
def _configuration_args(self, default=[]):
- args = self._downloader.params.get('postprocessor_args', {})
+ args = self.get_param('postprocessor_args', {})
if isinstance(args, list): # for backward compatibility
args = {'default': args, 'sponskrub': []}
return cli_configuration_args(args, self.PP_NAME.lower(), args.get('default', []))