Modified function cli_configuration_args

to directly parse new format of `postprocessor_args` and `external_downloader_args`
This commit is contained in:
pukkandan 2021-01-23 15:13:51 +05:30
parent 3bcaa37b1b
commit eab9b2bcaf
4 changed files with 37 additions and 54 deletions

View File

@ -18,7 +18,6 @@
)
from .compat import (
compat_getpass,
compat_shlex_split,
workaround_optparse_bug9161,
)
from .utils import (

View File

@ -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 """

View File

@ -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):

View File

@ -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):