add '-O/--postprocessor-option' command-line option (#3565)
This commit is contained in:
@@ -796,6 +796,24 @@ Description
|
|||||||
for each downloaded ``pixiv`` file.
|
for each downloaded ``pixiv`` file.
|
||||||
|
|
||||||
|
|
||||||
|
extractor.*.postprocessor-options
|
||||||
|
---------------------------------
|
||||||
|
Type
|
||||||
|
``object`` (`name` -> `value`)
|
||||||
|
Example
|
||||||
|
.. code:: json
|
||||||
|
|
||||||
|
{
|
||||||
|
"archive": null,
|
||||||
|
"keep-files": true
|
||||||
|
}
|
||||||
|
|
||||||
|
Description
|
||||||
|
Additional `Postprocessor Options`_ that get added to each individual
|
||||||
|
`post processor object <Postprocessor Configuration_>`__
|
||||||
|
before initializing it and evaluating filters.
|
||||||
|
|
||||||
|
|
||||||
extractor.*.retries
|
extractor.*.retries
|
||||||
-------------------
|
-------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -119,3 +119,6 @@
|
|||||||
successfully. Example: --exec-after "cd {} &&
|
successfully. Example: --exec-after "cd {} &&
|
||||||
convert * ../doc.pdf"
|
convert * ../doc.pdf"
|
||||||
-P, --postprocessor NAME Activate the specified post processor
|
-P, --postprocessor NAME Activate the specified post processor
|
||||||
|
-O, --postprocessor-option OPT
|
||||||
|
Additional '<key>=<value>' post processor
|
||||||
|
options
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2014-2022 Mike Fährmann
|
# Copyright 2014-2023 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -72,6 +72,8 @@ def main():
|
|||||||
else:
|
else:
|
||||||
profile, _, container = profile.partition("::")
|
profile, _, container = profile.partition("::")
|
||||||
config.set((), "cookies", (browser, profile, keyring, container))
|
config.set((), "cookies", (browser, profile, keyring, container))
|
||||||
|
if args.options_pp:
|
||||||
|
config.set((), "postprocessor-options", args.options_pp)
|
||||||
for opts in args.options:
|
for opts in args.options:
|
||||||
config.set(*opts)
|
config.set(*opts)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2015-2022 Mike Fährmann
|
# Copyright 2015-2023 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -473,13 +473,18 @@ class DownloadJob(Job):
|
|||||||
postprocessors = extr.config_accumulate("postprocessors")
|
postprocessors = extr.config_accumulate("postprocessors")
|
||||||
if postprocessors:
|
if postprocessors:
|
||||||
self.hooks = collections.defaultdict(list)
|
self.hooks = collections.defaultdict(list)
|
||||||
|
|
||||||
pp_log = self.get_logger("postprocessor")
|
pp_log = self.get_logger("postprocessor")
|
||||||
|
pp_conf = config.get((), "postprocessor") or {}
|
||||||
|
pp_opts = cfg("postprocessor-options")
|
||||||
pp_list = []
|
pp_list = []
|
||||||
|
|
||||||
pp_conf = config.get((), "postprocessor") or {}
|
|
||||||
for pp_dict in postprocessors:
|
for pp_dict in postprocessors:
|
||||||
if isinstance(pp_dict, str):
|
if isinstance(pp_dict, str):
|
||||||
pp_dict = pp_conf.get(pp_dict) or {"name": pp_dict}
|
pp_dict = pp_conf.get(pp_dict) or {"name": pp_dict}
|
||||||
|
if pp_opts:
|
||||||
|
pp_dict = pp_dict.copy()
|
||||||
|
pp_dict.update(pp_opts)
|
||||||
|
|
||||||
clist = pp_dict.get("whitelist")
|
clist = pp_dict.get("whitelist")
|
||||||
if clist is not None:
|
if clist is not None:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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
|
# 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
|
# 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):
|
class ParseAction(argparse.Action):
|
||||||
"""Parse <key>=<value> options and set them as config values"""
|
"""Parse <key>=<value> options and set them as config values"""
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
key, _, value = values.partition("=")
|
key, value = _parse_option(values)
|
||||||
try:
|
|
||||||
value = json.loads(value)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
key = key.split(".") # splitting an empty string becomes [""]
|
key = key.split(".") # splitting an empty string becomes [""]
|
||||||
namespace.options.append((key[:-1], key[-1], value))
|
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):
|
class Formatter(argparse.HelpFormatter):
|
||||||
"""Custom HelpFormatter class to customize help output"""
|
"""Custom HelpFormatter class to customize help output"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@@ -73,6 +76,15 @@ class Formatter(argparse.HelpFormatter):
|
|||||||
return self._metavar_formatter(action, action.dest)(1)[0]
|
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():
|
def build_parser():
|
||||||
"""Build and configure an ArgumentParser object"""
|
"""Build and configure an ArgumentParser object"""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@@ -488,6 +500,11 @@ def build_parser():
|
|||||||
dest="postprocessors", metavar="NAME", action="append",
|
dest="postprocessors", metavar="NAME", action="append",
|
||||||
help="Activate the specified post processor",
|
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(
|
parser.add_argument(
|
||||||
"urls",
|
"urls",
|
||||||
|
|||||||
Reference in New Issue
Block a user