]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python3 | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import optparse | |
5 | import os | |
6 | from os.path import dirname as dirn | |
7 | import sys | |
8 | ||
9 | sys.path.insert(0, dirn(dirn((os.path.abspath(__file__))))) | |
10 | import yt_dlp | |
11 | from yt_dlp.utils import shell_quote | |
12 | ||
13 | FISH_COMPLETION_FILE = 'completions/fish/yt-dlp.fish' | |
14 | FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in' | |
15 | ||
16 | EXTRA_ARGS = { | |
17 | 'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'], | |
18 | 'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'], | |
19 | ||
20 | # Options that need a file parameter | |
21 | 'download-archive': ['--require-parameter'], | |
22 | 'cookies': ['--require-parameter'], | |
23 | 'load-info': ['--require-parameter'], | |
24 | 'batch-file': ['--require-parameter'], | |
25 | } | |
26 | ||
27 | ||
28 | def build_completion(opt_parser): | |
29 | commands = [] | |
30 | ||
31 | for group in opt_parser.option_groups: | |
32 | for option in group.option_list: | |
33 | long_option = option.get_opt_string().strip('-') | |
34 | complete_cmd = ['complete', '--command', 'yt-dlp', '--long-option', long_option] | |
35 | if option._short_opts: | |
36 | complete_cmd += ['--short-option', option._short_opts[0].strip('-')] | |
37 | if option.help != optparse.SUPPRESS_HELP: | |
38 | complete_cmd += ['--description', option.help] | |
39 | complete_cmd.extend(EXTRA_ARGS.get(long_option, [])) | |
40 | commands.append(shell_quote(complete_cmd)) | |
41 | ||
42 | with open(FISH_COMPLETION_TEMPLATE) as f: | |
43 | template = f.read() | |
44 | filled_template = template.replace('{{commands}}', '\n'.join(commands)) | |
45 | with open(FISH_COMPLETION_FILE, 'w') as f: | |
46 | f.write(filled_template) | |
47 | ||
48 | ||
49 | parser = yt_dlp.parseOpts()[0] | |
50 | build_completion(parser) |