mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 06:10:12 +01:00
Improve argument parsing for -P
, -o
, -S
* `-P "subtitle,thumbnail:PATH"` is now possible. Similarly for `-o` * `-S "fps,br" -S "res,codec"` is now interpreted as `-S res,codec,fps,br`. Previously, `-S fps,br` was ignored in this case.
This commit is contained in:
parent
f8d4ad9ab0
commit
d818eb7473
|
@ -365,7 +365,7 @@ ## Filesystem Options:
|
||||||
stdin), one URL per line. Lines starting
|
stdin), one URL per line. Lines starting
|
||||||
with '#', ';' or ']' are considered as
|
with '#', ';' or ']' are considered as
|
||||||
comments and ignored
|
comments and ignored
|
||||||
-P, --paths TYPE:PATH The paths where the files should be
|
-P, --paths TYPES:PATH The paths where the files should be
|
||||||
downloaded. Specify the type of file and
|
downloaded. Specify the type of file and
|
||||||
the path separated by a colon ":". All the
|
the path separated by a colon ":". All the
|
||||||
same types as --output are supported.
|
same types as --output are supported.
|
||||||
|
@ -376,7 +376,7 @@ ## Filesystem Options:
|
||||||
home path after download is finished. This
|
home path after download is finished. This
|
||||||
option is ignored if --output is an
|
option is ignored if --output is an
|
||||||
absolute path
|
absolute path
|
||||||
-o, --output [TYPE:]TEMPLATE Output filename template, see "OUTPUT
|
-o, --output [TYPES:]TEMPLATE Output filename template; see "OUTPUT
|
||||||
TEMPLATE" for details
|
TEMPLATE" for details
|
||||||
--output-na-placeholder TEXT Placeholder value for unavailable meta
|
--output-na-placeholder TEXT Placeholder value for unavailable meta
|
||||||
fields in output filename template
|
fields in output filename template
|
||||||
|
|
|
@ -107,22 +107,31 @@ def _format_option_string(option):
|
||||||
|
|
||||||
return ''.join(opts)
|
return ''.join(opts)
|
||||||
|
|
||||||
def _comma_separated_values_options_callback(option, opt_str, value, parser):
|
def _comma_separated_values_options_callback(option, opt_str, value, parser, prepend=True):
|
||||||
setattr(parser.values, option.dest, value.split(','))
|
setattr(
|
||||||
|
parser.values, option.dest,
|
||||||
|
value.split(',') if not prepend
|
||||||
|
else value.split(',') + getattr(parser.values, option.dest))
|
||||||
|
|
||||||
def _dict_from_multiple_values_options_callback(
|
def _dict_from_multiple_values_options_callback(
|
||||||
option, opt_str, value, parser, allowed_keys=r'[\w-]+', delimiter=':', default_key=None, process=None):
|
option, opt_str, value, parser,
|
||||||
|
allowed_keys=r'[\w-]+', delimiter=':', default_key=None, process=None, multiple_keys=True):
|
||||||
|
|
||||||
out_dict = getattr(parser.values, option.dest)
|
out_dict = getattr(parser.values, option.dest)
|
||||||
mobj = re.match(r'(?i)(?P<key>%s)%s(?P<val>.*)$' % (allowed_keys, delimiter), value)
|
if multiple_keys:
|
||||||
|
allowed_keys = r'(%s)(,(%s))*' % (allowed_keys, allowed_keys)
|
||||||
|
mobj = re.match(r'(?i)(?P<keys>%s)%s(?P<val>.*)$' % (allowed_keys, delimiter), value)
|
||||||
if mobj is not None:
|
if mobj is not None:
|
||||||
key, val = mobj.group('key').lower(), mobj.group('val')
|
keys = [k.strip() for k in mobj.group('keys').lower().split(',')]
|
||||||
|
val = mobj.group('val')
|
||||||
elif default_key is not None:
|
elif default_key is not None:
|
||||||
key, val = default_key, value
|
keys, val = [default_key], value
|
||||||
else:
|
else:
|
||||||
raise optparse.OptionValueError(
|
raise optparse.OptionValueError(
|
||||||
'wrong %s formatting; it should be %s, not "%s"' % (opt_str, option.metavar, value))
|
'wrong %s formatting; it should be %s, not "%s"' % (opt_str, option.metavar, value))
|
||||||
out_dict[key] = process(val) if callable(process) else val
|
val = process(val) if callable(process) else val
|
||||||
|
for key in keys:
|
||||||
|
out_dict[key] = val
|
||||||
|
|
||||||
# No need to wrap help messages if we're on a wide console
|
# No need to wrap help messages if we're on a wide console
|
||||||
columns = compat_get_terminal_size().columns
|
columns = compat_get_terminal_size().columns
|
||||||
|
@ -693,6 +702,7 @@ def _dict_from_multiple_values_options_callback(
|
||||||
'--add-header',
|
'--add-header',
|
||||||
metavar='FIELD:VALUE', dest='headers', default={}, type='str',
|
metavar='FIELD:VALUE', dest='headers', default={}, type='str',
|
||||||
action='callback', callback=_dict_from_multiple_values_options_callback,
|
action='callback', callback=_dict_from_multiple_values_options_callback,
|
||||||
|
callback_kwargs={'multiple_keys': False},
|
||||||
help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
|
help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
|
||||||
)
|
)
|
||||||
workarounds.add_option(
|
workarounds.add_option(
|
||||||
|
@ -842,7 +852,7 @@ def _dict_from_multiple_values_options_callback(
|
||||||
action='store_true', dest='useid', help=optparse.SUPPRESS_HELP)
|
action='store_true', dest='useid', help=optparse.SUPPRESS_HELP)
|
||||||
filesystem.add_option(
|
filesystem.add_option(
|
||||||
'-P', '--paths',
|
'-P', '--paths',
|
||||||
metavar='TYPE:PATH', dest='paths', default={}, type='str',
|
metavar='TYPES:PATH', dest='paths', default={}, type='str',
|
||||||
action='callback', callback=_dict_from_multiple_values_options_callback,
|
action='callback', callback=_dict_from_multiple_values_options_callback,
|
||||||
callback_kwargs={
|
callback_kwargs={
|
||||||
'allowed_keys': 'home|temp|%s' % '|'.join(OUTTMPL_TYPES.keys()),
|
'allowed_keys': 'home|temp|%s' % '|'.join(OUTTMPL_TYPES.keys()),
|
||||||
|
@ -857,7 +867,7 @@ def _dict_from_multiple_values_options_callback(
|
||||||
'This option is ignored if --output is an absolute path'))
|
'This option is ignored if --output is an absolute path'))
|
||||||
filesystem.add_option(
|
filesystem.add_option(
|
||||||
'-o', '--output',
|
'-o', '--output',
|
||||||
metavar='[TYPE:]TEMPLATE', dest='outtmpl', default={}, type='str',
|
metavar='[TYPES:]TEMPLATE', dest='outtmpl', default={}, type='str',
|
||||||
action='callback', callback=_dict_from_multiple_values_options_callback,
|
action='callback', callback=_dict_from_multiple_values_options_callback,
|
||||||
callback_kwargs={
|
callback_kwargs={
|
||||||
'allowed_keys': '|'.join(OUTTMPL_TYPES.keys()),
|
'allowed_keys': '|'.join(OUTTMPL_TYPES.keys()),
|
||||||
|
@ -1084,7 +1094,9 @@ def _dict_from_multiple_values_options_callback(
|
||||||
'--postprocessor-args', '--ppa',
|
'--postprocessor-args', '--ppa',
|
||||||
metavar='NAME:ARGS', dest='postprocessor_args', default={}, type='str',
|
metavar='NAME:ARGS', dest='postprocessor_args', default={}, type='str',
|
||||||
action='callback', callback=_dict_from_multiple_values_options_callback,
|
action='callback', callback=_dict_from_multiple_values_options_callback,
|
||||||
callback_kwargs={'default_key': 'default-compat', 'allowed_keys': r'\w+(?:\+\w+)?', 'process': compat_shlex_split},
|
callback_kwargs={
|
||||||
|
'allowed_keys': r'\w+(?:\+\w+)?', 'default_key': 'default-compat',
|
||||||
|
'process': compat_shlex_split, 'multiple_keys': False},
|
||||||
help=(
|
help=(
|
||||||
'Give these arguments to the postprocessors. '
|
'Give these arguments to the postprocessors. '
|
||||||
'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
|
'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
|
||||||
|
|
Loading…
Reference in New Issue
Block a user