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