diff options
author | Jesus <heckyel@riseup.net> | 2023-09-04 01:59:36 +0800 |
---|---|---|
committer | Jesus <heckyel@riseup.net> | 2023-09-04 01:59:36 +0800 |
commit | b3013540b41d1eb77c4803c5fca46f8d75b40fc1 (patch) | |
tree | 97735cb0c49f3a2b0f276e1cd90817833d590d69 /devscripts/cli_to_api.py | |
parent | eaeeef9c1d1bedb76fea953c332ef84d53bffe2c (diff) | |
download | hypervideo-b3013540b41d1eb77c4803c5fca46f8d75b40fc1.tar.lz hypervideo-b3013540b41d1eb77c4803c5fca46f8d75b40fc1.tar.xz hypervideo-b3013540b41d1eb77c4803c5fca46f8d75b40fc1.zip |
update from upstream
Diffstat (limited to 'devscripts/cli_to_api.py')
-rw-r--r-- | devscripts/cli_to_api.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/devscripts/cli_to_api.py b/devscripts/cli_to_api.py new file mode 100644 index 0000000..563fa9e --- /dev/null +++ b/devscripts/cli_to_api.py @@ -0,0 +1,48 @@ +# Allow direct execution +import os +import sys + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import hypervideo_dl +import hypervideo_dl.options + +create_parser = hypervideo_dl.options.create_parser + + +def parse_patched_options(opts): + patched_parser = create_parser() + patched_parser.defaults.update({ + 'ignoreerrors': False, + 'retries': 0, + 'fragment_retries': 0, + 'extract_flat': False, + 'concat_playlist': 'never', + }) + hypervideo_dl.options.create_parser = lambda: patched_parser + try: + return hypervideo_dl.parse_options(opts) + finally: + hypervideo_dl.options.create_parser = create_parser + + +default_opts = parse_patched_options([]).ydl_opts + + +def cli_to_api(opts, cli_defaults=False): + opts = (hypervideo_dl.parse_options if cli_defaults else parse_patched_options)(opts).ydl_opts + + diff = {k: v for k, v in opts.items() if default_opts[k] != v} + if 'postprocessors' in diff: + diff['postprocessors'] = [pp for pp in diff['postprocessors'] + if pp not in default_opts['postprocessors']] + return diff + + +if __name__ == '__main__': + from pprint import pprint + + print('\nThe arguments passed translate to:\n') + pprint(cli_to_api(sys.argv[1:])) + print('\nCombining these with the CLI defaults gives:\n') + pprint(cli_to_api(sys.argv[1:], True)) |