From eab9b2bcafb42c47248f60ef0fdac14389693dd4 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sat, 23 Jan 2021 15:13:51 +0530 Subject: [PATCH] Modified function `cli_configuration_args` to directly parse new format of `postprocessor_args` and `external_downloader_args` --- youtube_dlc/__init__.py | 1 - youtube_dlc/downloader/external.py | 15 ++--------- youtube_dlc/postprocessor/common.py | 40 +++++------------------------ youtube_dlc/utils.py | 35 ++++++++++++++++++++----- 4 files changed, 37 insertions(+), 54 deletions(-) diff --git a/youtube_dlc/__init__.py b/youtube_dlc/__init__.py index c58fb7563..2072165ce 100644 --- a/youtube_dlc/__init__.py +++ b/youtube_dlc/__init__.py @@ -18,7 +18,6 @@ ) from .compat import ( compat_getpass, - compat_shlex_split, workaround_optparse_bug9161, ) from .utils import ( diff --git a/youtube_dlc/downloader/external.py b/youtube_dlc/downloader/external.py index 2ae153f4a..f3a0d0ce4 100644 --- a/youtube_dlc/downloader/external.py +++ b/youtube_dlc/downloader/external.py @@ -95,19 +95,8 @@ def _valueless_option(self, command_option, param, expected_value=True): return cli_valueless_option(self.params, command_option, param, expected_value) def _configuration_args(self, default=[]): - args = self.params.get('external_downloader_args', {}) - if isinstance(args, (list, tuple)): # for backward compatibility - return args - if args is None: - return default - assert isinstance(args, dict) - - dl_args = args.get(self.get_basename().lower()) - if dl_args is None: - dl_args = args.get('default', default) - assert isinstance(dl_args, (list, tuple)) - return dl_args - + return cli_configuration_args( + self.params, 'external_downloader_args', self.get_basename(), default)[0] def _call_downloader(self, tmpfilename, info_dict): """ Either overwrite this or implement _make_cmd """ diff --git a/youtube_dlc/postprocessor/common.py b/youtube_dlc/postprocessor/common.py index 5b777fad1..7fb85413f 100644 --- a/youtube_dlc/postprocessor/common.py +++ b/youtube_dlc/postprocessor/common.py @@ -4,8 +4,9 @@ from ..compat import compat_str from ..utils import ( - PostProcessingError, + cli_configuration_args, encodeFilename, + PostProcessingError, ) @@ -91,39 +92,10 @@ def try_utime(self, path, atime, mtime, errnote='Cannot update utime of file'): self.report_warning(errnote) def _configuration_args(self, default=[], exe=None): - args = self.get_param('postprocessor_args', {}) - pp_key = self.pp_key().lower() - - if isinstance(args, (list, tuple)): # for backward compatibility - return default if pp_key == 'sponskrub' else args - if args is None: - return default - assert isinstance(args, dict) - - exe_args = None - if exe is not None: - assert isinstance(exe, compat_str) - exe = exe.lower() - specific_args = args.get('%s+%s' % (pp_key, exe)) - if specific_args is not None: - assert isinstance(specific_args, (list, tuple)) - return specific_args - exe_args = args.get(exe) - - pp_args = args.get(pp_key) if pp_key != exe else None - if pp_args is None and exe_args is None: - default = args.get('default', default) - assert isinstance(default, (list, tuple)) - return default - - if pp_args is None: - pp_args = [] - elif exe_args is None: - exe_args = [] - - assert isinstance(pp_args, (list, tuple)) - assert isinstance(exe_args, (list, tuple)) - return pp_args + exe_args + key = self.pp_key().lower() + args, is_compat = cli_configuration_args( + self._downloader.params, 'postprocessor_args', key, default, exe) + return args if not is_compat or key != 'sponskrub' else default class AudioConversionError(PostProcessingError): diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index 8cecaa8ee..1ec30bafd 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -4656,12 +4656,35 @@ def cli_valueless_option(params, command_option, param, expected_value=True): return [command_option] if param == expected_value else [] -def cli_configuration_args(params, param, default=[]): - ex_args = params.get(param) - if ex_args is None: - return default - assert isinstance(ex_args, list) - return ex_args +def cli_configuration_args(params, arg_name, key, default=[], exe=None): # returns arg, for_compat + argdict = params.get(arg_name, {}) + if isinstance(argdict, (list, tuple)): # for backward compatibility + return argdict, True + + if argdict is None: + return default, False + assert isinstance(argdict, dict) + + assert isinstance(key, compat_str) + key = key.lower() + + args = exe_args = None + if exe is not None: + assert isinstance(exe, compat_str) + exe = exe.lower() + args = argdict.get('%s+%s' % (key, exe)) + if args is None: + exe_args = argdict.get(exe) + + if args is None: + args = argdict.get(key) if key != exe else None + if args is None and exe_args is None: + args = argdict.get('default', default) + + args, exe_args = args or [], exe_args or [] + assert isinstance(args, (list, tuple)) + assert isinstance(exe_args, (list, tuple)) + return args + exe_args, False class ISO639Utils(object):