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