2021-06-03 05:43:42 -04:00
|
|
|
#!/usr/bin/env python3
|
2014-09-14 08:07:33 -04:00
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2022-04-11 20:01:54 -04:00
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
2021-02-24 13:45:56 -05:00
|
|
|
import yt_dlp
|
|
|
|
from yt_dlp.utils import shell_quote
|
2014-09-14 08:07:33 -04:00
|
|
|
|
2021-02-25 09:49:57 -05:00
|
|
|
FISH_COMPLETION_FILE = 'completions/fish/yt-dlp.fish'
|
2014-09-14 08:07:33 -04:00
|
|
|
FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in'
|
|
|
|
|
|
|
|
EXTRA_ARGS = {
|
2020-05-16 12:09:12 -04:00
|
|
|
'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'],
|
2014-09-14 08:07:33 -04: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 14:41:03 -05:00
|
|
|
|
2014-09-14 08:07:33 -04: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 13:45:56 -05:00
|
|
|
complete_cmd = ['complete', '--command', 'yt-dlp', '--long-option', long_option]
|
2014-09-14 08:07:33 -04: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 06:42:56 -05:00
|
|
|
|
2021-02-24 13:45:56 -05:00
|
|
|
parser = yt_dlp.parseOpts()[0]
|
2014-09-14 08:07:33 -04:00
|
|
|
build_completion(parser)
|