]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python3 | |
2 | ||
3 | # Allow direct execution | |
4 | import os | |
5 | import sys | |
6 | ||
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
8 | ||
9 | import yt_dlp | |
10 | import yt_dlp.options | |
11 | ||
12 | create_parser = yt_dlp.options.create_parser | |
13 | ||
14 | ||
15 | def parse_patched_options(opts): | |
16 | patched_parser = create_parser() | |
17 | patched_parser.defaults.update({ | |
18 | 'ignoreerrors': False, | |
19 | 'retries': 0, | |
20 | 'fragment_retries': 0, | |
21 | 'extract_flat': False, | |
22 | 'concat_playlist': 'never', | |
23 | }) | |
24 | yt_dlp.options.create_parser = lambda: patched_parser | |
25 | try: | |
26 | return yt_dlp.parse_options(opts) | |
27 | finally: | |
28 | yt_dlp.options.create_parser = create_parser | |
29 | ||
30 | ||
31 | default_opts = parse_patched_options([]).ydl_opts | |
32 | ||
33 | ||
34 | def cli_to_api(opts, cli_defaults=False): | |
35 | opts = (yt_dlp.parse_options if cli_defaults else parse_patched_options)(opts).ydl_opts | |
36 | ||
37 | diff = {k: v for k, v in opts.items() if default_opts[k] != v} | |
38 | if 'postprocessors' in diff: | |
39 | diff['postprocessors'] = [pp for pp in diff['postprocessors'] | |
40 | if pp not in default_opts['postprocessors']] | |
41 | return diff | |
42 | ||
43 | ||
44 | if __name__ == '__main__': | |
45 | from pprint import pprint | |
46 | ||
47 | print('\nThe arguments passed translate to:\n') | |
48 | pprint(cli_to_api(sys.argv[1:])) | |
49 | print('\nCombining these with the CLI defaults gives:\n') | |
50 | pprint(cli_to_api(sys.argv[1:], True)) |