2017-03-23 16:29:40 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2021-03-02 23:59:34 +01:00
|
|
|
# Copyright 2017-2021 Mike Fährmann
|
2017-03-23 16:29:40 +01:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
|
|
|
"""Command line option parsing"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import json
|
2019-06-29 23:46:55 +02:00
|
|
|
import sys
|
2019-05-10 22:05:57 +02:00
|
|
|
from . import job, version
|
2017-03-23 16:29:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ConfigAction(argparse.Action):
|
|
|
|
"""Set argparse results as config values"""
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
2019-11-23 23:50:16 +01:00
|
|
|
namespace.options.append(((), self.dest, values))
|
2017-03-23 16:29:40 +01:00
|
|
|
|
|
|
|
|
2017-05-03 15:17:08 +02:00
|
|
|
class ConfigConstAction(argparse.Action):
|
|
|
|
"""Set argparse const values as config values"""
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
2019-11-23 23:50:16 +01:00
|
|
|
namespace.options.append(((), self.dest, self.const))
|
2017-05-03 15:17:08 +02:00
|
|
|
|
|
|
|
|
2019-10-05 23:33:51 +02:00
|
|
|
class AppendCommandAction(argparse.Action):
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
|
|
items = getattr(namespace, self.dest, None) or []
|
|
|
|
val = self.const.copy()
|
|
|
|
val["command"] = values
|
|
|
|
items.append(val)
|
|
|
|
setattr(namespace, self.dest, items)
|
|
|
|
|
|
|
|
|
2019-06-29 23:46:55 +02:00
|
|
|
class DeprecatedConfigConstAction(argparse.Action):
|
|
|
|
"""Set argparse const values as config values + deprecation warning"""
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
|
|
print("warning: {} is deprecated. Use {} instead.".format(
|
|
|
|
"/".join(self.option_strings), self.choices), file=sys.stderr)
|
2019-11-23 23:50:16 +01:00
|
|
|
namespace.options.append(((), self.dest, self.const))
|
2019-06-29 23:46:55 +02:00
|
|
|
|
|
|
|
|
2017-03-23 16:29:40 +01:00
|
|
|
class ParseAction(argparse.Action):
|
|
|
|
"""Parse <key>=<value> options and set them as config values"""
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
2018-01-27 01:05:17 +01:00
|
|
|
key, _, value = values.partition("=")
|
2017-03-23 16:29:40 +01:00
|
|
|
try:
|
2018-01-27 01:05:17 +01:00
|
|
|
value = json.loads(value)
|
2017-03-23 16:29:40 +01:00
|
|
|
except ValueError:
|
2018-01-27 01:05:17 +01:00
|
|
|
pass
|
2019-11-23 23:50:16 +01:00
|
|
|
key = key.split(".") # splitting an empty string becomes [""]
|
|
|
|
namespace.options.append((key[:-1], key[-1], value))
|
2017-03-23 16:29:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Formatter(argparse.HelpFormatter):
|
|
|
|
"""Custom HelpFormatter class to customize help output"""
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-03-23 16:51:42 +01:00
|
|
|
super().__init__(max_help_position=50, *args, **kwargs)
|
2017-03-23 16:29:40 +01:00
|
|
|
|
|
|
|
def _format_action_invocation(self, action):
|
|
|
|
opts = action.option_strings[:]
|
|
|
|
if opts:
|
|
|
|
if action.nargs != 0:
|
|
|
|
args_string = self._format_args(action, "ARG")
|
|
|
|
opts[-1] += " " + args_string
|
|
|
|
return ', '.join(opts)
|
|
|
|
else:
|
|
|
|
return self._metavar_formatter(action, action.dest)(1)[0]
|
|
|
|
|
|
|
|
|
|
|
|
def build_parser():
|
|
|
|
"""Build and configure an ArgumentParser object"""
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
usage="%(prog)s [OPTION]... URL...",
|
|
|
|
formatter_class=Formatter,
|
2017-08-16 19:56:50 +02:00
|
|
|
add_help=False,
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
|
|
|
general = parser.add_argument_group("General Options")
|
|
|
|
general.add_argument(
|
|
|
|
"-h", "--help",
|
|
|
|
action="help",
|
2017-09-30 18:52:23 +02:00
|
|
|
help="Print this help message and exit",
|
2017-08-16 19:56:50 +02:00
|
|
|
)
|
|
|
|
general.add_argument(
|
|
|
|
"--version",
|
2019-05-10 22:05:57 +02:00
|
|
|
action="version", version=version.__version__,
|
2017-08-16 19:56:50 +02:00
|
|
|
help="Print program version and exit",
|
|
|
|
)
|
|
|
|
general.add_argument(
|
|
|
|
"-i", "--input-file",
|
2021-03-04 21:37:26 +01:00
|
|
|
dest="inputfiles", metavar="FILE", action="append",
|
|
|
|
help=("Download URLs found in FILE ('-' for stdin). "
|
|
|
|
"More than one --input-file can be specified"),
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2022-01-03 18:30:36 +01:00
|
|
|
general.add_argument(
|
|
|
|
"-d", "--destination",
|
|
|
|
dest="base-directory", metavar="PATH", action=ConfigAction,
|
|
|
|
help="Target location for file downloads",
|
|
|
|
)
|
|
|
|
general.add_argument(
|
|
|
|
"-D", "--directory",
|
|
|
|
dest="directory", metavar="PATH",
|
|
|
|
help="Exact location for file downloads",
|
|
|
|
)
|
2021-12-27 23:31:54 +01:00
|
|
|
general.add_argument(
|
|
|
|
"-f", "--filename",
|
|
|
|
dest="filename", metavar="FORMAT",
|
|
|
|
help=("Filename format string for downloaded files "
|
|
|
|
"('/O' for \"original\" filenames)"),
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
general.add_argument(
|
|
|
|
"--cookies",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="cookies", metavar="FILE", action=ConfigAction,
|
2017-08-16 19:56:50 +02:00
|
|
|
help="File to load additional cookies from",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2018-02-19 18:24:56 +01:00
|
|
|
general.add_argument(
|
|
|
|
"--proxy",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="proxy", metavar="URL", action=ConfigAction,
|
2018-02-19 18:24:56 +01:00
|
|
|
help="Use the specified proxy",
|
|
|
|
)
|
2022-01-20 23:16:00 +01:00
|
|
|
general.add_argument(
|
|
|
|
"--source-address",
|
|
|
|
dest="source-address", metavar="IP", action=ConfigAction,
|
|
|
|
help="Client-side IP address to bind to",
|
|
|
|
)
|
2019-04-25 21:30:16 +02:00
|
|
|
general.add_argument(
|
|
|
|
"--clear-cache",
|
2021-06-11 23:18:49 +02:00
|
|
|
dest="clear_cache", metavar="MODULE",
|
|
|
|
help="Delete cached login sessions, cookies, etc. for MODULE "
|
|
|
|
"(ALL to delete everything)",
|
2019-04-25 21:30:16 +02:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
|
|
|
output = parser.add_argument_group("Output Options")
|
|
|
|
output.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"-q", "--quiet",
|
|
|
|
dest="loglevel", default=logging.INFO,
|
|
|
|
action="store_const", const=logging.ERROR,
|
2017-08-16 19:56:50 +02:00
|
|
|
help="Activate quiet mode",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
output.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"-v", "--verbose",
|
|
|
|
dest="loglevel",
|
|
|
|
action="store_const", const=logging.DEBUG,
|
2017-08-16 19:56:50 +02:00
|
|
|
help="Print various debugging information",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
output.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"-g", "--get-urls",
|
|
|
|
dest="list_urls", action="count",
|
2017-08-16 19:56:50 +02:00
|
|
|
help="Print URLs instead of downloading",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2021-01-07 18:10:54 +01:00
|
|
|
output.add_argument(
|
2021-01-26 01:01:22 +01:00
|
|
|
"-G", "--resolve-urls",
|
2021-01-07 18:10:54 +01:00
|
|
|
dest="list_urls", action="store_const", const=128,
|
2021-01-26 01:01:22 +01:00
|
|
|
help="Print URLs instead of downloading; resolve intermediary URLs",
|
2021-01-07 18:10:54 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
output.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"-j", "--dump-json",
|
|
|
|
dest="jobtype", action="store_const", const=job.DataJob,
|
2017-08-16 19:56:50 +02:00
|
|
|
help="Print JSON information",
|
2017-05-03 15:17:08 +02:00
|
|
|
)
|
2018-05-25 16:07:18 +02:00
|
|
|
output.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"-s", "--simulate",
|
|
|
|
dest="jobtype", action="store_const", const=job.SimulationJob,
|
2018-05-25 16:07:18 +02:00
|
|
|
help="Simulate data extraction; do not download anything",
|
|
|
|
)
|
2021-03-02 23:59:34 +01:00
|
|
|
output.add_argument(
|
|
|
|
"-E", "--extractor-info",
|
|
|
|
dest="jobtype", action="store_const", const=job.InfoJob,
|
|
|
|
help="Print extractor defaults and settings",
|
|
|
|
)
|
2017-09-09 18:48:28 +02:00
|
|
|
output.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"-K", "--list-keywords",
|
|
|
|
dest="jobtype", action="store_const", const=job.KeywordJob,
|
2017-09-30 18:52:23 +02:00
|
|
|
help=("Print a list of available keywords and example values "
|
|
|
|
"for the given URLs"),
|
2017-09-09 18:48:28 +02:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
output.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"--list-modules",
|
|
|
|
dest="list_modules", action="store_true",
|
2017-08-16 19:56:50 +02:00
|
|
|
help="Print a list of available extractor modules",
|
|
|
|
)
|
|
|
|
output.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"--list-extractors",
|
|
|
|
dest="list_extractors", action="store_true",
|
2017-08-16 19:56:50 +02:00
|
|
|
help=("Print a list of extractor classes "
|
|
|
|
"with description, (sub)category and example URL"),
|
|
|
|
)
|
2018-01-26 18:51:51 +01:00
|
|
|
output.add_argument(
|
|
|
|
"--write-log",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="logfile", metavar="FILE", action=ConfigAction,
|
2018-10-07 21:34:25 +02:00
|
|
|
help="Write logging output to FILE",
|
2018-01-26 18:51:51 +01:00
|
|
|
)
|
|
|
|
output.add_argument(
|
|
|
|
"--write-unsupported",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="unsupportedfile", metavar="FILE", action=ConfigAction,
|
2018-01-26 18:51:51 +01:00
|
|
|
help=("Write URLs, which get emitted by other extractors but cannot "
|
|
|
|
"be handled, to FILE"),
|
|
|
|
)
|
2020-05-12 14:25:21 +02:00
|
|
|
output.add_argument(
|
|
|
|
"--write-pages",
|
2020-05-12 20:40:25 +02:00
|
|
|
dest="write-pages", nargs=0, action=ConfigConstAction, const=True,
|
2020-05-12 14:25:21 +02:00
|
|
|
help=("Write downloaded intermediary pages to files "
|
|
|
|
"in the current directory to debug problems"),
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
|
|
|
downloader = parser.add_argument_group("Downloader Options")
|
2017-12-02 01:47:26 +01:00
|
|
|
downloader.add_argument(
|
|
|
|
"-r", "--limit-rate",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="rate", metavar="RATE", action=ConfigAction,
|
2017-12-02 01:47:26 +01:00
|
|
|
help="Maximum download rate (e.g. 500k or 2.5M)",
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
downloader.add_argument(
|
2017-03-23 16:29:40 +01:00
|
|
|
"-R", "--retries",
|
2019-06-30 22:55:31 +02:00
|
|
|
dest="retries", metavar="N", type=int, action=ConfigAction,
|
|
|
|
help=("Maximum number of retries for failed HTTP requests "
|
|
|
|
"or -1 for infinite retries (default: 4)"),
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
downloader.add_argument(
|
2017-03-23 16:29:40 +01:00
|
|
|
"--http-timeout",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="timeout", metavar="SECONDS", type=float, action=ConfigAction,
|
2020-05-14 23:37:15 +02:00
|
|
|
help="Timeout for HTTP connections (default: 30.0)",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-12-04 17:06:17 +01:00
|
|
|
downloader.add_argument(
|
|
|
|
"--sleep",
|
2021-12-19 03:17:56 +01:00
|
|
|
dest="sleep", metavar="SECONDS", action=ConfigAction,
|
|
|
|
help=("Number of seconds to wait before each download. "
|
|
|
|
"This can be either a constant value or a range "
|
|
|
|
"(e.g. 2.7 or 2.0-3.5)"),
|
|
|
|
)
|
|
|
|
downloader.add_argument(
|
|
|
|
"--sleep-request",
|
|
|
|
dest="sleep-request", metavar="SECONDS", action=ConfigAction,
|
|
|
|
help=("Number of seconds to wait between HTTP requests "
|
|
|
|
"during data extraction"),
|
|
|
|
)
|
|
|
|
downloader.add_argument(
|
|
|
|
"--sleep-extractor",
|
|
|
|
dest="sleep-extractor", metavar="SECONDS", action=ConfigAction,
|
|
|
|
help=("Number of seconds to wait before starting data extraction "
|
|
|
|
"for an input URL"),
|
2017-12-04 17:06:17 +01:00
|
|
|
)
|
2020-09-01 22:05:17 +02:00
|
|
|
downloader.add_argument(
|
|
|
|
"--filesize-min",
|
|
|
|
dest="filesize-min", metavar="SIZE", action=ConfigAction,
|
|
|
|
help="Do not download files smaller than SIZE (e.g. 500k or 2.5M)",
|
|
|
|
)
|
|
|
|
downloader.add_argument(
|
|
|
|
"--filesize-max",
|
|
|
|
dest="filesize-max", metavar="SIZE", action=ConfigAction,
|
|
|
|
help="Do not download files larger than SIZE (e.g. 500k or 2.5M)",
|
|
|
|
)
|
2017-10-24 23:33:44 +02:00
|
|
|
downloader.add_argument(
|
|
|
|
"--no-part",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="part", nargs=0, action=ConfigConstAction, const=False,
|
2017-10-24 23:33:44 +02:00
|
|
|
help="Do not use .part files",
|
|
|
|
)
|
2020-09-10 22:15:51 +02:00
|
|
|
downloader.add_argument(
|
|
|
|
"--no-skip",
|
|
|
|
dest="skip", nargs=0, action=ConfigConstAction, const=False,
|
|
|
|
help="Do not skip downloads; overwrite existing files",
|
|
|
|
)
|
2019-06-20 17:19:44 +02:00
|
|
|
downloader.add_argument(
|
|
|
|
"--no-mtime",
|
|
|
|
dest="mtime", nargs=0, action=ConfigConstAction, const=False,
|
|
|
|
help=("Do not set file modification times according to "
|
|
|
|
"Last-Modified HTTP response headers")
|
|
|
|
)
|
2019-07-13 21:49:26 +02:00
|
|
|
downloader.add_argument(
|
|
|
|
"--no-download",
|
|
|
|
dest="download", nargs=0, action=ConfigConstAction, const=False,
|
|
|
|
help=("Do not download any files")
|
|
|
|
)
|
2018-10-07 21:46:00 +02:00
|
|
|
downloader.add_argument(
|
|
|
|
"--no-check-certificate",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="verify", nargs=0, action=ConfigConstAction, const=False,
|
2018-10-07 21:46:00 +02:00
|
|
|
help="Disable HTTPS certificate validation",
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
|
|
|
configuration = parser.add_argument_group("Configuration Options")
|
|
|
|
configuration.add_argument(
|
2017-03-23 16:29:40 +01:00
|
|
|
"-c", "--config",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="cfgfiles", metavar="FILE", action="append",
|
2017-03-23 16:29:40 +01:00
|
|
|
help="Additional configuration files",
|
|
|
|
)
|
2019-05-10 22:05:57 +02:00
|
|
|
configuration.add_argument(
|
|
|
|
"--config-yaml",
|
|
|
|
dest="yamlfiles", metavar="FILE", action="append",
|
|
|
|
help=argparse.SUPPRESS,
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
configuration.add_argument(
|
2018-10-07 21:34:25 +02:00
|
|
|
"-o", "--option",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="options", metavar="OPT", action=ParseAction, default=[],
|
2018-10-07 21:34:25 +02:00
|
|
|
help="Additional '<key>=<value>' option values",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
configuration.add_argument(
|
2019-05-10 22:05:57 +02:00
|
|
|
"--ignore-config",
|
|
|
|
dest="load_config", action="store_false",
|
2017-04-25 17:09:10 +02:00
|
|
|
help="Do not read the default configuration files",
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
|
|
|
authentication = parser.add_argument_group("Authentication Options")
|
|
|
|
authentication.add_argument(
|
|
|
|
"-u", "--username",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="username", metavar="USER", action=ConfigAction,
|
|
|
|
help="Username to login with",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
authentication.add_argument(
|
|
|
|
"-p", "--password",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="password", metavar="PASS", action=ConfigAction,
|
|
|
|
help="Password belonging to the given username",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
authentication.add_argument(
|
|
|
|
"--netrc",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="netrc", nargs=0, action=ConfigConstAction, const=True,
|
2017-12-05 23:29:11 +01:00
|
|
|
help="Enable .netrc authentication data",
|
2017-04-26 11:33:19 +02:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
|
|
|
selection = parser.add_argument_group("Selection Options")
|
2018-02-01 22:00:44 +01:00
|
|
|
selection.add_argument(
|
|
|
|
"--download-archive",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="archive", metavar="FILE", action=ConfigAction,
|
2018-02-01 22:00:44 +01:00
|
|
|
help=("Record all downloaded files in the archive file and "
|
2021-06-05 04:00:29 +02:00
|
|
|
"skip downloading any file already in it"),
|
|
|
|
)
|
|
|
|
selection.add_argument(
|
|
|
|
"-A", "--abort",
|
|
|
|
dest="abort", metavar="N", type=int,
|
|
|
|
help=("Stop current extractor run "
|
|
|
|
"after N consecutive file downloads were skipped"),
|
|
|
|
)
|
|
|
|
selection.add_argument(
|
|
|
|
"-T", "--terminate",
|
|
|
|
dest="terminate", metavar="N", type=int,
|
|
|
|
help=("Stop current and parent extractor runs "
|
|
|
|
"after N consecutive file downloads were skipped"),
|
2018-02-01 22:00:44 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
selection.add_argument(
|
2017-09-23 17:31:40 +02:00
|
|
|
"--range",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="image-range", metavar="RANGE", action=ConfigAction,
|
|
|
|
help=("Index-range(s) specifying which images to download. "
|
|
|
|
"For example '5-10' or '1,3-5,10-'"),
|
2017-04-18 11:38:48 +02:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
selection.add_argument(
|
2017-09-23 17:31:40 +02:00
|
|
|
"--chapter-range",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="chapter-range", metavar="RANGE", action=ConfigAction,
|
2018-10-07 21:34:25 +02:00
|
|
|
help=("Like '--range', but applies to manga-chapters "
|
2017-10-09 23:20:17 +02:00
|
|
|
"and other delegated URLs"),
|
2017-09-08 17:52:00 +02:00
|
|
|
)
|
|
|
|
selection.add_argument(
|
|
|
|
"--filter",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="image-filter", metavar="EXPR", action=ConfigAction,
|
2018-10-07 21:34:25 +02:00
|
|
|
help=("Python expression controlling which images to download. "
|
|
|
|
"Files for which the expression evaluates to False are ignored. "
|
2017-12-05 23:29:11 +01:00
|
|
|
"Available keys are the filename-specific ones listed by '-K'. "
|
|
|
|
"Example: --filter \"image_width >= 1000 and "
|
2017-09-08 17:52:00 +02:00
|
|
|
"rating in ('s', 'q')\""),
|
|
|
|
)
|
|
|
|
selection.add_argument(
|
|
|
|
"--chapter-filter",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="chapter-filter", metavar="EXPR", action=ConfigAction,
|
2018-10-07 21:34:25 +02:00
|
|
|
help=("Like '--filter', but applies to manga-chapters "
|
2017-10-09 23:20:17 +02:00
|
|
|
"and other delegated URLs"),
|
2017-09-23 17:31:40 +02:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
2021-12-21 00:21:39 +01:00
|
|
|
infojson = {
|
|
|
|
"name" : "metadata",
|
|
|
|
"event" : "init",
|
|
|
|
"filename": "info.json",
|
|
|
|
}
|
2018-06-18 18:14:38 +02:00
|
|
|
postprocessor = parser.add_argument_group("Post-processing Options")
|
|
|
|
postprocessor.add_argument(
|
|
|
|
"--zip",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="postprocessors",
|
2021-06-05 01:37:47 +02:00
|
|
|
action="append_const", const="zip",
|
2018-06-18 18:14:38 +02:00
|
|
|
help="Store downloaded files in a ZIP archive",
|
|
|
|
)
|
|
|
|
postprocessor.add_argument(
|
|
|
|
"--ugoira-conv",
|
2019-10-26 00:32:19 +02:00
|
|
|
dest="postprocessors", action="append_const", const={
|
|
|
|
"name" : "ugoira",
|
|
|
|
"ffmpeg-args" : ("-c:v", "libvpx", "-crf", "4", "-b:v", "5000k"),
|
|
|
|
"ffmpeg-twopass": True,
|
|
|
|
"whitelist" : ("pixiv", "danbooru"),
|
|
|
|
},
|
2018-06-18 19:22:54 +02:00
|
|
|
help="Convert Pixiv Ugoira to WebM (requires FFmpeg)",
|
2018-06-18 18:14:38 +02:00
|
|
|
)
|
2019-10-26 00:32:19 +02:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--ugoira-conv-lossless",
|
|
|
|
dest="postprocessors", action="append_const", const={
|
|
|
|
"name" : "ugoira",
|
|
|
|
"ffmpeg-args" : ("-c:v", "libvpx-vp9", "-lossless", "1",
|
|
|
|
"-pix_fmt", "yuv420p"),
|
|
|
|
"ffmpeg-twopass": False,
|
|
|
|
"whitelist" : ("pixiv", "danbooru"),
|
|
|
|
},
|
|
|
|
help="Convert Pixiv Ugoira to WebM in VP9 lossless mode",
|
|
|
|
)
|
2019-01-05 16:39:05 +01:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--write-metadata",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="postprocessors",
|
2021-06-05 01:37:47 +02:00
|
|
|
action="append_const", const="metadata",
|
2019-01-05 16:39:05 +01:00
|
|
|
help="Write metadata to separate JSON files",
|
|
|
|
)
|
2021-09-23 17:58:40 +02:00
|
|
|
postprocessor.add_argument(
|
2021-12-21 00:21:39 +01:00
|
|
|
"--write-info-json",
|
2021-09-23 17:58:40 +02:00
|
|
|
dest="postprocessors",
|
2021-12-21 00:21:39 +01:00
|
|
|
action="append_const", const=infojson,
|
2021-09-23 17:58:40 +02:00
|
|
|
help="Write gallery metadata to a info.json file",
|
|
|
|
)
|
2021-12-21 00:21:39 +01:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--write-infojson",
|
|
|
|
dest="postprocessors",
|
|
|
|
action="append_const", const=infojson,
|
|
|
|
help=argparse.SUPPRESS,
|
|
|
|
)
|
2019-01-23 21:43:22 +01:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--write-tags",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="postprocessors",
|
|
|
|
action="append_const", const={"name": "metadata", "mode": "tags"},
|
2019-01-23 21:43:22 +01:00
|
|
|
help="Write image tags to separate text files",
|
|
|
|
)
|
2019-07-14 22:37:28 +02:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--mtime-from-date",
|
|
|
|
dest="postprocessors",
|
2021-06-05 01:37:47 +02:00
|
|
|
action="append_const", const="mtime",
|
2019-07-14 22:37:28 +02:00
|
|
|
help="Set file modification times according to 'date' metadata",
|
|
|
|
)
|
2019-11-27 19:42:46 +01:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--exec",
|
|
|
|
dest="postprocessors", metavar="CMD",
|
|
|
|
action=AppendCommandAction, const={"name": "exec"},
|
|
|
|
help=("Execute CMD for each downloaded file. "
|
|
|
|
"Example: --exec 'convert {} {}.png && rm {}'"),
|
|
|
|
)
|
|
|
|
postprocessor.add_argument(
|
|
|
|
"--exec-after",
|
|
|
|
dest="postprocessors", metavar="CMD",
|
2020-11-19 01:31:52 +01:00
|
|
|
action=AppendCommandAction, const={
|
|
|
|
"name": "exec", "event": "finalize"},
|
2019-11-27 19:42:46 +01:00
|
|
|
help=("Execute CMD after all files were downloaded successfully. "
|
|
|
|
"Example: --exec-after 'cd {} && convert * ../doc.pdf'"),
|
|
|
|
)
|
2021-06-05 03:14:34 +02:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"-P", "--postprocessor",
|
|
|
|
dest="postprocessors", metavar="NAME", action="append",
|
|
|
|
help="Activate the specified post processor",
|
|
|
|
)
|
2018-06-18 18:14:38 +02:00
|
|
|
|
2017-03-23 16:29:40 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"urls",
|
2019-05-10 22:05:57 +02:00
|
|
|
metavar="URL", nargs="*",
|
2017-08-16 19:56:50 +02:00
|
|
|
help=argparse.SUPPRESS,
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
2017-03-23 16:29:40 +01:00
|
|
|
return parser
|