mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 13:12:45 +01:00
Modified function cli_configuration_args
to directly parse new format of `postprocessor_args` and `external_downloader_args`
This commit is contained in:
parent
3bcaa37b1b
commit
eab9b2bcaf
@ -18,7 +18,6 @@
|
|||||||
)
|
)
|
||||||
from .compat import (
|
from .compat import (
|
||||||
compat_getpass,
|
compat_getpass,
|
||||||
compat_shlex_split,
|
|
||||||
workaround_optparse_bug9161,
|
workaround_optparse_bug9161,
|
||||||
)
|
)
|
||||||
from .utils import (
|
from .utils import (
|
||||||
|
@ -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)
|
return cli_valueless_option(self.params, command_option, param, expected_value)
|
||||||
|
|
||||||
def _configuration_args(self, default=[]):
|
def _configuration_args(self, default=[]):
|
||||||
args = self.params.get('external_downloader_args', {})
|
return cli_configuration_args(
|
||||||
if isinstance(args, (list, tuple)): # for backward compatibility
|
self.params, 'external_downloader_args', self.get_basename(), default)[0]
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def _call_downloader(self, tmpfilename, info_dict):
|
def _call_downloader(self, tmpfilename, info_dict):
|
||||||
""" Either overwrite this or implement _make_cmd """
|
""" Either overwrite this or implement _make_cmd """
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
from ..compat import compat_str
|
from ..compat import compat_str
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
PostProcessingError,
|
cli_configuration_args,
|
||||||
encodeFilename,
|
encodeFilename,
|
||||||
|
PostProcessingError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -91,39 +92,10 @@ def try_utime(self, path, atime, mtime, errnote='Cannot update utime of file'):
|
|||||||
self.report_warning(errnote)
|
self.report_warning(errnote)
|
||||||
|
|
||||||
def _configuration_args(self, default=[], exe=None):
|
def _configuration_args(self, default=[], exe=None):
|
||||||
args = self.get_param('postprocessor_args', {})
|
key = self.pp_key().lower()
|
||||||
pp_key = self.pp_key().lower()
|
args, is_compat = cli_configuration_args(
|
||||||
|
self._downloader.params, 'postprocessor_args', key, default, exe)
|
||||||
if isinstance(args, (list, tuple)): # for backward compatibility
|
return args if not is_compat or key != 'sponskrub' else default
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class AudioConversionError(PostProcessingError):
|
class AudioConversionError(PostProcessingError):
|
||||||
|
@ -4656,12 +4656,35 @@ def cli_valueless_option(params, command_option, param, expected_value=True):
|
|||||||
return [command_option] if param == expected_value else []
|
return [command_option] if param == expected_value else []
|
||||||
|
|
||||||
|
|
||||||
def cli_configuration_args(params, param, default=[]):
|
def cli_configuration_args(params, arg_name, key, default=[], exe=None): # returns arg, for_compat
|
||||||
ex_args = params.get(param)
|
argdict = params.get(arg_name, {})
|
||||||
if ex_args is None:
|
if isinstance(argdict, (list, tuple)): # for backward compatibility
|
||||||
return default
|
return argdict, True
|
||||||
assert isinstance(ex_args, list)
|
|
||||||
return ex_args
|
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):
|
class ISO639Utils(object):
|
||||||
|
Loading…
Reference in New Issue
Block a user