diff options
Diffstat (limited to 'gallery_dl/option.py')
| -rw-r--r-- | gallery_dl/option.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/gallery_dl/option.py b/gallery_dl/option.py index 32cac79..213cd2d 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2017-2022 Mike Fährmann +# Copyright 2017-2023 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -48,15 +48,18 @@ class DeprecatedConfigConstAction(argparse.Action): class ParseAction(argparse.Action): """Parse <key>=<value> options and set them as config values""" def __call__(self, parser, namespace, values, option_string=None): - key, _, value = values.partition("=") - try: - value = json.loads(value) - except ValueError: - pass + key, value = _parse_option(values) key = key.split(".") # splitting an empty string becomes [""] namespace.options.append((key[:-1], key[-1], value)) +class OptionAction(argparse.Action): + """Parse <key>=<value> options for """ + def __call__(self, parser, namespace, values, option_string=None): + key, value = _parse_option(values) + namespace.options_pp[key] = value + + class Formatter(argparse.HelpFormatter): """Custom HelpFormatter class to customize help output""" def __init__(self, *args, **kwargs): @@ -73,6 +76,15 @@ class Formatter(argparse.HelpFormatter): return self._metavar_formatter(action, action.dest)(1)[0] +def _parse_option(opt): + key, _, value = opt.partition("=") + try: + value = json.loads(value) + except ValueError: + pass + return key, value + + def build_parser(): """Build and configure an ArgumentParser object""" parser = argparse.ArgumentParser( @@ -488,6 +500,11 @@ def build_parser(): dest="postprocessors", metavar="NAME", action="append", help="Activate the specified post processor", ) + postprocessor.add_argument( + "-O", "--postprocessor-option", + dest="options_pp", metavar="OPT", action=OptionAction, default={}, + help="Additional '<key>=<value>' post processor options", + ) parser.add_argument( "urls", |
