mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-04-13 12:19:48 +00:00
Add preset alias help output
This commit is contained in:
parent
afa79173cd
commit
f93fdcbc06
@ -150,6 +150,15 @@ class _YoutubeDLHelpFormatter(optparse.IndentedHelpFormatter):
|
||||
return opts
|
||||
|
||||
|
||||
_PRESET_ALIASES = {
|
||||
'mp3': ['-f', 'ba[acodec=mp3]/ba/b', '-x', '--audio-format', 'mp3'],
|
||||
'aac': ['-f', 'ba[acodec*=aac]/ba[acodec^=mp4a.40.]/ba/b', '-x', '--audio-format', 'aac'],
|
||||
'mp4': ['--merge-output-format', 'mp4', '--remux', 'mp4', '-S', 'vcodec:h264,lang,quality,res,fps,hdr:12,acodec:aac'],
|
||||
'mkv': ['--merge-output-format', 'mkv', '--remux', 'mkv'],
|
||||
'embed': ['--embed-subs', '--embed-thumbnail', '--embed-metadata'],
|
||||
}
|
||||
|
||||
|
||||
class _YoutubeDLOptionParser(optparse.OptionParser):
|
||||
# optparse is deprecated since Python 3.2. So assume a stable interface even for private methods
|
||||
ALIAS_DEST = '_triggered_aliases'
|
||||
@ -215,6 +224,21 @@ class _YoutubeDLOptionParser(optparse.OptionParser):
|
||||
return e.possibilities[0]
|
||||
raise
|
||||
|
||||
def format_option_help(self, formatter=None):
|
||||
assert formatter, ''
|
||||
formatted_help = super().format_option_help(formatter=formatter)
|
||||
formatter.indent()
|
||||
heading = formatter.format_heading('Preset aliases')
|
||||
formatter.indent()
|
||||
result = []
|
||||
for name, args in _PRESET_ALIASES.items():
|
||||
option = optparse.Option('-t', help=shlex.join(args))
|
||||
formatter.option_strings[option] = f'-t {name}'
|
||||
result.append(formatter.format_option(option))
|
||||
formatter.dedent()
|
||||
formatter.dedent()
|
||||
return f'{formatted_help}\n{heading}{"\n".join(result)}'
|
||||
|
||||
|
||||
def create_parser():
|
||||
def _list_from_options_callback(option, opt_str, value, parser, append=True, delim=',', process=str.strip):
|
||||
@ -317,20 +341,12 @@ def create_parser():
|
||||
parser.rargs[:0] = shlex.split(
|
||||
opts if value is None else opts.format(*map(shlex.quote, value)))
|
||||
|
||||
PRESET_ALIASES = {
|
||||
'mp3': ['-f', 'ba[acodec=mp3]/ba/b', '-x', '--audio-format', 'mp3'],
|
||||
'aac': ['-f', 'ba[acodec*=aac]/ba[acodec^=mp4a.40.]/ba/b', '-x', '--audio-format', 'aac'],
|
||||
'mp4': ['--merge-output-format', 'mp4', '--remux', 'mp4', '-S', 'vcodec:h264,lang,quality,res,fps,hdr:12,acodec:aac'],
|
||||
'mkv': ['--merge-output-format', 'mkv', '--remux', 'mkv'],
|
||||
'embed': ['--embed-subs', '--embed-thumbnail', '--embed-metadata'],
|
||||
}
|
||||
|
||||
def _preset_alias_callback(option, opt_str, value, parser):
|
||||
if not value:
|
||||
return
|
||||
if value not in PRESET_ALIASES:
|
||||
if value not in _PRESET_ALIASES:
|
||||
raise optparse.OptionValueError(f'Unknown preset alias: {value}')
|
||||
parser.rargs[:0] = PRESET_ALIASES[value]
|
||||
parser.rargs[:0] = _PRESET_ALIASES[value]
|
||||
|
||||
general = optparse.OptionGroup(parser, 'General Options')
|
||||
general.add_option(
|
||||
@ -539,7 +555,8 @@ def create_parser():
|
||||
action='callback', callback=_preset_alias_callback,
|
||||
help=(
|
||||
'Applies a predefined preset. e.g. --preset-alias mp3. '
|
||||
f'The following presets are available: {", ".join(PRESET_ALIASES)}. '
|
||||
f'The following presets are available: {", ".join(_PRESET_ALIASES)}. '
|
||||
'See the "Preset aliases" section at the end for more infos. '
|
||||
'This option can be used multiple times.'))
|
||||
|
||||
network = optparse.OptionGroup(parser, 'Network Options')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user