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