2021-06-03 03:43:42 -06:00
|
|
|
#!/usr/bin/env python3
|
2014-09-14 06:07:33 -06:00
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2022-04-11 18:01:54 -06:00
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
2021-02-24 11:45:56 -07:00
|
|
|
import yt_dlp
|
|
|
|
from yt_dlp.utils import shell_quote
|
2014-09-14 06:07:33 -06:00
|
|
|
|
2021-02-25 07:49:57 -07:00
|
|
|
FISH_COMPLETION_FILE = 'completions/fish/yt-dlp.fish'
|
2014-09-14 06:07:33 -06:00
|
|
|
FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in'
|
|
|
|
|
|
|
|
EXTRA_ARGS = {
|
2020-05-16 10:09:12 -06:00
|
|
|
'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'],
|
2014-09-14 06:07:33 -06:00
|
|
|
'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'],
|
|
|
|
|
|
|
|
# Options that need a file parameter
|
|
|
|
'download-archive': ['--require-parameter'],
|
|
|
|
'cookies': ['--require-parameter'],
|
|
|
|
'load-info': ['--require-parameter'],
|
|
|
|
'batch-file': ['--require-parameter'],
|
|
|
|
}
|
|
|
|
|
2014-11-23 12:41:03 -07:00
|
|
|
|
2014-09-14 06:07:33 -06:00
|
|
|
def build_completion(opt_parser):
|
|
|
|
commands = []
|
|
|
|
|
|
|
|
for group in opt_parser.option_groups:
|
|
|
|
for option in group.option_list:
|
|
|
|
long_option = option.get_opt_string().strip('-')
|
2021-02-24 11:45:56 -07:00
|
|
|
complete_cmd = ['complete', '--command', 'yt-dlp', '--long-option', long_option]
|
2014-09-14 06:07:33 -06:00
|
|
|
if option._short_opts:
|
|
|
|
complete_cmd += ['--short-option', option._short_opts[0].strip('-')]
|
|
|
|
if option.help != optparse.SUPPRESS_HELP:
|
|
|
|
complete_cmd += ['--description', option.help]
|
|
|
|
complete_cmd.extend(EXTRA_ARGS.get(long_option, []))
|
|
|
|
commands.append(shell_quote(complete_cmd))
|
|
|
|
|
|
|
|
with open(FISH_COMPLETION_TEMPLATE) as f:
|
|
|
|
template = f.read()
|
|
|
|
filled_template = template.replace('{{commands}}', '\n'.join(commands))
|
|
|
|
with open(FISH_COMPLETION_FILE, 'w') as f:
|
|
|
|
f.write(filled_template)
|
|
|
|
|
2016-11-17 04:42:56 -07:00
|
|
|
|
2022-04-27 02:15:45 -06:00
|
|
|
parser = yt_dlp.parseOpts(ignore_config_files=True)[0]
|
2014-09-14 06:07:33 -06:00
|
|
|
build_completion(parser)
|