summaryrefslogtreecommitdiffstats
path: root/gallery_dl/option.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2023-01-30 04:40:57 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2023-01-30 04:40:57 -0500
commit919f8ba16a7b82ba1099bd25b2c61c7881a05aa2 (patch)
tree50eb34c3286538164a2f2b7048d110dc89b2a971 /gallery_dl/option.py
parentf1051085013c0d702ef974b9b27ea43b3fc73259 (diff)
New upstream version 1.24.5.upstream/1.24.5
Diffstat (limited to 'gallery_dl/option.py')
-rw-r--r--gallery_dl/option.py29
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",