2017-03-23 16:29:40 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-01-26 14:59:24 +01:00
|
|
|
# Copyright 2017-2023 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
|
2019-06-29 23:46:55 +02:00
|
|
|
import sys
|
2023-02-07 23:14:53 +01:00
|
|
|
from . import job, util, 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):
|
2022-05-19 13:24:37 +02:00
|
|
|
sys.stderr.write(
|
|
|
|
"warning: {} is deprecated. Use {} instead.\n".format(
|
|
|
|
"/".join(self.option_strings), self.choices))
|
2019-11-23 23:50:16 +01:00
|
|
|
namespace.options.append(((), self.dest, self.const))
|
2019-06-29 23:46:55 +02:00
|
|
|
|
|
|
|
|
2023-11-15 14:59:03 +01:00
|
|
|
class ConfigParseAction(argparse.Action):
|
|
|
|
"""Parse KEY=VALUE config options"""
|
2017-03-23 16:29:40 +01:00
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
2023-01-26 14:59:24 +01:00
|
|
|
key, value = _parse_option(values)
|
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
|
|
|
|
|
|
|
|
2023-11-15 14:59:03 +01:00
|
|
|
class PPParseAction(argparse.Action):
|
|
|
|
"""Parse KEY=VALUE post processor options"""
|
2023-01-26 14:59:24 +01:00
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
|
|
key, value = _parse_option(values)
|
|
|
|
namespace.options_pp[key] = value
|
|
|
|
|
|
|
|
|
2023-11-14 20:38:11 +01:00
|
|
|
class InputfileAction(argparse.Action):
|
2023-11-15 14:59:03 +01:00
|
|
|
"""Collect input files"""
|
2023-11-14 20:38:11 +01:00
|
|
|
def __call__(self, parser, namespace, value, option_string=None):
|
|
|
|
namespace.input_files.append((value, self.const))
|
|
|
|
|
|
|
|
|
2023-11-15 15:01:02 +01:00
|
|
|
class MtimeAction(argparse.Action):
|
2023-11-16 17:15:17 +01:00
|
|
|
"""Configure mtime post processors"""
|
2023-11-15 15:01:02 +01:00
|
|
|
def __call__(self, parser, namespace, value, option_string=None):
|
|
|
|
namespace.postprocessors.append({
|
|
|
|
"name": "mtime",
|
|
|
|
"value": "{" + (self.const or value) + "}",
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2023-11-16 17:15:17 +01:00
|
|
|
class UgoiraAction(argparse.Action):
|
|
|
|
"""Configure ugoira post processors"""
|
|
|
|
def __call__(self, parser, namespace, value, option_string=None):
|
|
|
|
if self.const:
|
|
|
|
value = self.const
|
|
|
|
else:
|
|
|
|
value = value.strip().lower()
|
|
|
|
|
|
|
|
if value in ("webm", "vp9"):
|
|
|
|
pp = {
|
|
|
|
"extension" : "webm",
|
|
|
|
"ffmpeg-args" : ("-c:v", "libvpx-vp9",
|
|
|
|
"-crf", "12",
|
|
|
|
"-b:v", "0", "-an"),
|
|
|
|
}
|
|
|
|
elif value == "vp9-lossless":
|
|
|
|
pp = {
|
|
|
|
"extension" : "webm",
|
|
|
|
"ffmpeg-args" : ("-c:v", "libvpx-vp9",
|
|
|
|
"-lossless", "1",
|
|
|
|
"-pix_fmt", "yuv420p", "-an"),
|
|
|
|
}
|
|
|
|
elif value == "vp8":
|
|
|
|
pp = {
|
|
|
|
"extension" : "webm",
|
|
|
|
"ffmpeg-args" : ("-c:v", "libvpx",
|
|
|
|
"-crf", "4",
|
|
|
|
"-b:v", "5000k", "-an"),
|
|
|
|
}
|
|
|
|
elif value == "mp4":
|
|
|
|
pp = {
|
|
|
|
"extension" : "mp4",
|
|
|
|
"ffmpeg-args" : ("-c:v", "libx264", "-an", "-b:v", "5M"),
|
|
|
|
"libx264-prevent-odd": True,
|
|
|
|
}
|
|
|
|
elif value == "gif":
|
|
|
|
pp = {
|
|
|
|
"extension" : "gif",
|
|
|
|
"ffmpeg-args" : ("-filter_complex", "[0:v] split [a][b];"
|
|
|
|
"[a] palettegen [p];[b][p] paletteuse"),
|
|
|
|
"repeat-last-frame": False,
|
|
|
|
}
|
|
|
|
elif value in ("mkv", "copy"):
|
|
|
|
pp = {
|
|
|
|
"extension" : "mkv",
|
|
|
|
"ffmpeg-args" : ("-c:v", "copy"),
|
|
|
|
"repeat-last-frame": False,
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
parser.error("Unsupported Ugoira format '{}'".format(value))
|
|
|
|
|
|
|
|
pp["name"] = "ugoira"
|
|
|
|
pp["whitelist"] = ("pixiv", "danbooru")
|
|
|
|
|
|
|
|
namespace.options.append(((), "ugoira", True))
|
|
|
|
namespace.postprocessors.append(pp)
|
|
|
|
|
|
|
|
|
2017-03-23 16:29:40 +01:00
|
|
|
class Formatter(argparse.HelpFormatter):
|
|
|
|
"""Custom HelpFormatter class to customize help output"""
|
2023-02-28 20:26:20 +01:00
|
|
|
def __init__(self, prog):
|
|
|
|
argparse.HelpFormatter.__init__(self, prog, max_help_position=30)
|
|
|
|
|
|
|
|
def _format_action_invocation(self, action, join=", ".join):
|
|
|
|
opts = action.option_strings
|
|
|
|
if action.metavar:
|
|
|
|
opts = opts.copy()
|
|
|
|
opts[-1] += " " + action.metavar
|
|
|
|
return join(opts)
|
2017-03-23 16:29:40 +01:00
|
|
|
|
|
|
|
|
2023-01-26 14:59:24 +01:00
|
|
|
def _parse_option(opt):
|
|
|
|
key, _, value = opt.partition("=")
|
|
|
|
try:
|
2023-02-07 23:14:53 +01:00
|
|
|
value = util.json_loads(value)
|
2023-01-26 14:59:24 +01:00
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
return key, value
|
|
|
|
|
|
|
|
|
2017-03-23 16:29:40 +01:00
|
|
|
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",
|
|
|
|
)
|
2023-01-30 20:07:18 +01:00
|
|
|
general.add_argument(
|
|
|
|
"-f", "--filename",
|
|
|
|
dest="filename", metavar="FORMAT",
|
|
|
|
help=("Filename format string for downloaded files "
|
|
|
|
"('/O' for \"original\" filenames)"),
|
|
|
|
)
|
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(
|
2023-01-30 20:07:18 +01:00
|
|
|
"-X", "--extractors",
|
|
|
|
dest="extractor_sources", metavar="PATH", action="append",
|
|
|
|
help="Load external extractors from PATH",
|
2021-12-27 23:31:54 +01:00
|
|
|
)
|
2022-11-02 21:59:47 +01:00
|
|
|
general.add_argument(
|
|
|
|
"--user-agent",
|
|
|
|
dest="user-agent", metavar="UA", action=ConfigAction,
|
|
|
|
help="User-Agent request header",
|
|
|
|
)
|
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
|
|
|
|
2024-06-15 23:29:09 +02:00
|
|
|
update = parser.add_argument_group("Update Options")
|
2024-08-12 08:00:59 +02:00
|
|
|
if util.EXECUTABLE:
|
2024-06-15 23:29:09 +02:00
|
|
|
update.add_argument(
|
|
|
|
"-U", "--update",
|
|
|
|
dest="update", action="store_const", const="latest",
|
|
|
|
help="Update to the latest version",
|
|
|
|
)
|
|
|
|
update.add_argument(
|
|
|
|
"--update-to",
|
|
|
|
dest="update", metavar="CHANNEL[@TAG]",
|
|
|
|
help=("Switch to a dfferent release channel (stable or dev) "
|
|
|
|
"or upgrade/downgrade to a specific version"),
|
|
|
|
)
|
|
|
|
update.add_argument(
|
|
|
|
"--update-check",
|
|
|
|
dest="update", action="store_const", const="check",
|
|
|
|
help="Check if a newer version is available",
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
update.add_argument(
|
|
|
|
"-U", "--update-check",
|
|
|
|
dest="update", action="store_const", const="check",
|
|
|
|
help="Check if a newer version is available",
|
|
|
|
)
|
|
|
|
|
2023-11-14 20:38:11 +01:00
|
|
|
input = parser.add_argument_group("Input Options")
|
|
|
|
input.add_argument(
|
|
|
|
"urls",
|
|
|
|
metavar="URL", nargs="*",
|
|
|
|
help=argparse.SUPPRESS,
|
|
|
|
)
|
|
|
|
input.add_argument(
|
|
|
|
"-i", "--input-file",
|
|
|
|
dest="input_files", metavar="FILE", action=InputfileAction, const=None,
|
|
|
|
default=[],
|
|
|
|
help=("Download URLs found in FILE ('-' for stdin). "
|
|
|
|
"More than one --input-file can be specified"),
|
|
|
|
)
|
|
|
|
input.add_argument(
|
|
|
|
"-I", "--input-file-comment",
|
|
|
|
dest="input_files", metavar="FILE", action=InputfileAction, const="c",
|
|
|
|
help=("Download URLs found in FILE. "
|
|
|
|
"Comment them out after they were downloaded successfully."),
|
|
|
|
)
|
|
|
|
input.add_argument(
|
|
|
|
"-x", "--input-file-delete",
|
|
|
|
dest="input_files", metavar="FILE", action=InputfileAction, const="d",
|
|
|
|
help=("Download URLs found in FILE. "
|
|
|
|
"Delete them after they were downloaded successfully."),
|
|
|
|
)
|
2024-06-16 18:31:39 +02:00
|
|
|
input.add_argument(
|
|
|
|
"--no-input",
|
|
|
|
dest="input", nargs=0, action=ConfigConstAction, const=False,
|
|
|
|
help=("Do not prompt for passwords/tokens"),
|
|
|
|
)
|
2023-11-14 20:38:11 +01: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(
|
2024-04-14 15:15:07 +02:00
|
|
|
"-w", "--warning",
|
2019-05-10 22:05:57 +02:00
|
|
|
dest="loglevel",
|
2024-04-14 15:15:07 +02:00
|
|
|
action="store_const", const=logging.WARNING,
|
|
|
|
help="Print only warnings and errors",
|
2017-03-23 16:29:40 +01:00
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
output.add_argument(
|
2024-04-14 15:15:07 +02:00
|
|
|
"-v", "--verbose",
|
2024-04-14 10:55:50 +02:00
|
|
|
dest="loglevel",
|
2024-04-14 15:15:07 +02:00
|
|
|
action="store_const", const=logging.DEBUG,
|
|
|
|
help="Print various debugging information",
|
2024-04-14 10:55: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",
|
2024-07-26 20:36:04 +02:00
|
|
|
dest="dump_json", action="count",
|
2017-08-16 19:56:50 +02:00
|
|
|
help="Print JSON information",
|
2017-05-03 15:17:08 +02:00
|
|
|
)
|
2024-07-26 20:36:04 +02:00
|
|
|
output.add_argument(
|
|
|
|
"-J", "--resolve-json",
|
|
|
|
dest="dump_json", action="store_const", const=128,
|
|
|
|
help="Print JSON information; resolve intermediary URLs",
|
|
|
|
)
|
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
|
|
|
)
|
2023-12-05 20:49:51 +01:00
|
|
|
output.add_argument(
|
|
|
|
"-e", "--error-file",
|
2023-12-10 00:00:57 +01:00
|
|
|
dest="errorfile", metavar="FILE", action=ConfigAction,
|
2023-12-05 20:49:51 +01:00
|
|
|
help="Add input URLs which returned an error to FILE",
|
|
|
|
)
|
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"),
|
|
|
|
)
|
2024-07-05 03:22:06 +02:00
|
|
|
output.add_argument(
|
|
|
|
"--print-traffic",
|
|
|
|
dest="print_traffic", action="store_true",
|
|
|
|
help=("Display sent and read HTTP traffic"),
|
|
|
|
)
|
2024-04-20 21:00:26 +02:00
|
|
|
output.add_argument(
|
|
|
|
"--no-colors",
|
|
|
|
dest="colors", action="store_false",
|
|
|
|
help=("Do not emit ANSI color codes in output"),
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
2024-06-15 23:29:09 +02:00
|
|
|
networking = parser.add_argument_group("Networking Options")
|
|
|
|
networking.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
|
|
|
)
|
2024-06-15 23:29:09 +02:00
|
|
|
networking.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
|
|
|
)
|
2024-06-15 23:29:09 +02:00
|
|
|
networking.add_argument(
|
|
|
|
"--proxy",
|
|
|
|
dest="proxy", metavar="URL", action=ConfigAction,
|
|
|
|
help="Use the specified proxy",
|
|
|
|
)
|
|
|
|
networking.add_argument(
|
|
|
|
"--source-address",
|
|
|
|
dest="source-address", metavar="IP", action=ConfigAction,
|
|
|
|
help="Client-side IP address to bind to",
|
|
|
|
)
|
|
|
|
networking.add_argument(
|
|
|
|
"--no-check-certificate",
|
|
|
|
dest="verify", nargs=0, action=ConfigConstAction, const=False,
|
|
|
|
help="Disable HTTPS certificate validation",
|
|
|
|
)
|
|
|
|
|
|
|
|
downloader = parser.add_argument_group("Downloader Options")
|
|
|
|
downloader.add_argument(
|
|
|
|
"-r", "--limit-rate",
|
|
|
|
dest="rate", metavar="RATE", action=ConfigAction,
|
|
|
|
help="Maximum download rate (e.g. 500k or 2.5M)",
|
|
|
|
)
|
|
|
|
downloader.add_argument(
|
|
|
|
"--chunk-size",
|
|
|
|
dest="chunk-size", metavar="SIZE", action=ConfigAction,
|
|
|
|
help="Size of in-memory data chunks (default: 32k)",
|
|
|
|
)
|
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
|
|
|
)
|
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")
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
|
|
|
|
configuration = parser.add_argument_group("Configuration Options")
|
2023-02-28 21:54:46 +01:00
|
|
|
configuration.add_argument(
|
|
|
|
"-o", "--option",
|
2023-11-15 14:59:03 +01:00
|
|
|
dest="options", metavar="KEY=VALUE",
|
|
|
|
action=ConfigParseAction, default=[],
|
2023-02-28 21:54:46 +01:00
|
|
|
help=("Additional options. "
|
|
|
|
"Example: -o browser=firefox") ,
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
configuration.add_argument(
|
2017-03-23 16:29:40 +01:00
|
|
|
"-c", "--config",
|
2023-02-28 21:54:46 +01:00
|
|
|
dest="configs_json", 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",
|
2023-02-28 21:54:46 +01:00
|
|
|
dest="configs_yaml", metavar="FILE", action="append",
|
|
|
|
help="Additional configuration files in YAML format",
|
|
|
|
)
|
|
|
|
configuration.add_argument(
|
|
|
|
"--config-toml",
|
|
|
|
dest="configs_toml", metavar="FILE", action="append",
|
|
|
|
help="Additional configuration files in TOML format",
|
2019-05-10 22:05:57 +02:00
|
|
|
)
|
2023-03-01 14:49:40 +01:00
|
|
|
configuration.add_argument(
|
|
|
|
"--config-create",
|
2024-06-13 23:08:11 +02:00
|
|
|
dest="config", action="store_const", const="init",
|
2023-03-01 14:49:40 +01:00
|
|
|
help="Create a basic configuration file",
|
|
|
|
)
|
2024-06-13 23:08:11 +02:00
|
|
|
configuration.add_argument(
|
|
|
|
"--config-status",
|
|
|
|
dest="config", action="store_const", const="status",
|
|
|
|
help="Show configuration file status",
|
|
|
|
)
|
|
|
|
configuration.add_argument(
|
|
|
|
"--config-open",
|
|
|
|
dest="config", action="store_const", const="open",
|
|
|
|
help="Open configuration file in external application",
|
|
|
|
)
|
2017-08-16 19:56:50 +02:00
|
|
|
configuration.add_argument(
|
2023-02-28 21:07:42 +01:00
|
|
|
"--config-ignore",
|
2023-03-01 14:49:40 +01:00
|
|
|
dest="config_load", action="store_false",
|
2023-02-28 21:07:42 +01:00
|
|
|
help="Do not read default configuration files",
|
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",
|
2023-03-01 14:49:40 +01:00
|
|
|
dest="config_load", action="store_false",
|
2023-02-28 21:07:42 +01:00
|
|
|
help=argparse.SUPPRESS,
|
|
|
|
)
|
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
|
|
|
|
2023-05-06 17:40:55 +02:00
|
|
|
cookies = parser.add_argument_group("Cookie Options")
|
|
|
|
cookies.add_argument(
|
|
|
|
"-C", "--cookies",
|
|
|
|
dest="cookies", metavar="FILE", action=ConfigAction,
|
|
|
|
help="File to load additional cookies from",
|
|
|
|
)
|
|
|
|
cookies.add_argument(
|
|
|
|
"--cookies-export",
|
|
|
|
dest="cookies-update", metavar="FILE", action=ConfigAction,
|
|
|
|
help="Export session cookies to FILE",
|
|
|
|
)
|
|
|
|
cookies.add_argument(
|
|
|
|
"--cookies-from-browser",
|
|
|
|
dest="cookies_from_browser",
|
|
|
|
metavar="BROWSER[/DOMAIN][+KEYRING][:PROFILE][::CONTAINER]",
|
|
|
|
help=("Name of the browser to load cookies from, with optional "
|
|
|
|
"domain prefixed with '/', "
|
|
|
|
"keyring name prefixed with '+', "
|
|
|
|
"profile prefixed with ':', and "
|
2024-08-14 18:34:17 +02:00
|
|
|
"container prefixed with '::' "
|
|
|
|
"('none' for no container (default), 'all' for all containers)"),
|
2023-05-06 17:40:55 +02:00
|
|
|
)
|
|
|
|
|
2017-08-16 19:56:50 +02:00
|
|
|
selection = parser.add_argument_group("Selection Options")
|
2021-06-05 04:00:29 +02:00
|
|
|
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
|
|
|
)
|
2024-06-15 23:29:09 +02:00
|
|
|
selection.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)",
|
|
|
|
)
|
|
|
|
selection.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)",
|
|
|
|
)
|
|
|
|
selection.add_argument(
|
|
|
|
"--download-archive",
|
|
|
|
dest="archive", metavar="FILE", action=ConfigAction,
|
|
|
|
help=("Record all downloaded or skipped files in FILE and "
|
|
|
|
"skip downloading any file already in it"),
|
|
|
|
)
|
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,
|
2022-12-27 18:21:12 +01:00
|
|
|
help=("Index range(s) specifying which files to download. "
|
|
|
|
"These can be either a constant value, range, or slice "
|
|
|
|
"(e.g. '5', '8-20', or '1:24:3')"),
|
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,
|
2022-12-27 18:21:12 +01: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,
|
2022-12-27 18:21:12 +01:00
|
|
|
help=("Python expression controlling which files to download. "
|
2018-10-07 21:34:25 +02:00
|
|
|
"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,
|
2022-12-27 18:21:12 +01: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(
|
2023-11-16 17:37:15 +01:00
|
|
|
"-P", "--postprocessor",
|
|
|
|
dest="postprocessors", metavar="NAME", action="append", default=[],
|
|
|
|
help="Activate the specified post processor",
|
2019-10-26 00:32:19 +02:00
|
|
|
)
|
2024-06-15 23:29:09 +02:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--no-postprocessors",
|
|
|
|
dest="postprocess", nargs=0, action=ConfigConstAction, const=False,
|
|
|
|
help=("Do not run any post processors")
|
|
|
|
)
|
2022-03-27 15:31:24 +02:00
|
|
|
postprocessor.add_argument(
|
2023-11-16 17:37:15 +01:00
|
|
|
"-O", "--postprocessor-option",
|
|
|
|
dest="options_pp", metavar="KEY=VALUE",
|
|
|
|
action=PPParseAction, default={},
|
|
|
|
help="Additional post processor options",
|
2022-03-27 15:31:24 +02:00
|
|
|
)
|
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",
|
|
|
|
)
|
2023-11-16 17:37:15 +01:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--zip",
|
|
|
|
dest="postprocessors",
|
|
|
|
action="append_const", const="zip",
|
|
|
|
help="Store downloaded files in a ZIP archive",
|
|
|
|
)
|
|
|
|
postprocessor.add_argument(
|
|
|
|
"--cbz",
|
|
|
|
dest="postprocessors",
|
|
|
|
action="append_const", const={
|
|
|
|
"name" : "zip",
|
|
|
|
"extension": "cbz",
|
|
|
|
},
|
|
|
|
help="Store downloaded files in a CBZ archive",
|
|
|
|
)
|
2023-11-15 15:01:02 +01:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--mtime",
|
2023-11-16 17:37:15 +01:00
|
|
|
dest="postprocessors", metavar="NAME", action=MtimeAction,
|
2023-11-15 15:01:02 +01:00
|
|
|
help=("Set file modification times according to metadata "
|
2023-11-16 17:37:15 +01:00
|
|
|
"selected by NAME. Examples: 'date' or 'status[date]'"),
|
2023-11-15 15:01:02 +01:00
|
|
|
)
|
2019-07-14 22:37:28 +02:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--mtime-from-date",
|
2023-11-15 15:01:02 +01:00
|
|
|
dest="postprocessors", nargs=0, action=MtimeAction,
|
|
|
|
const="date|status[date]",
|
|
|
|
help=argparse.SUPPRESS,
|
2019-07-14 22:37:28 +02:00
|
|
|
)
|
2023-11-16 17:37:15 +01:00
|
|
|
postprocessor.add_argument(
|
|
|
|
"--ugoira",
|
|
|
|
dest="postprocessors", metavar="FORMAT", action=UgoiraAction,
|
|
|
|
help=("Convert Pixiv Ugoira to FORMAT using FFmpeg. "
|
|
|
|
"Supported formats are 'webm', 'mp4', 'gif', "
|
|
|
|
"'vp8', 'vp9', 'vp9-lossless', 'copy'."),
|
|
|
|
)
|
|
|
|
postprocessor.add_argument(
|
|
|
|
"--ugoira-conv",
|
|
|
|
dest="postprocessors", nargs=0, action=UgoiraAction, const="vp8",
|
|
|
|
help=argparse.SUPPRESS,
|
|
|
|
)
|
|
|
|
postprocessor.add_argument(
|
|
|
|
"--ugoira-conv-lossless",
|
|
|
|
dest="postprocessors", nargs=0, action=UgoiraAction,
|
|
|
|
const="vp9-lossless",
|
|
|
|
help=argparse.SUPPRESS,
|
|
|
|
)
|
|
|
|
postprocessor.add_argument(
|
|
|
|
"--ugoira-conv-copy",
|
|
|
|
dest="postprocessors", nargs=0, action=UgoiraAction, const="copy",
|
|
|
|
help=argparse.SUPPRESS,
|
|
|
|
)
|
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. "
|
2023-10-09 12:50:10 +02:00
|
|
|
"Supported replacement fields are "
|
|
|
|
"{} or {_path}, {_directory}, {_filename}. "
|
2023-01-04 14:30:27 +01:00
|
|
|
"Example: --exec \"convert {} {}.png && rm {}\""),
|
2019-11-27 19:42:46 +01:00
|
|
|
)
|
|
|
|
postprocessor.add_argument(
|
|
|
|
"--exec-after",
|
|
|
|
dest="postprocessors", metavar="CMD",
|
2020-11-19 01:31:52 +01:00
|
|
|
action=AppendCommandAction, const={
|
|
|
|
"name": "exec", "event": "finalize"},
|
2023-11-16 17:37:15 +01:00
|
|
|
help=("Execute CMD after all files were downloaded. "
|
2023-10-09 12:50:10 +02:00
|
|
|
"Example: --exec-after \"cd {_directory} "
|
|
|
|
"&& convert * ../doc.pdf\""),
|
2019-11-27 19:42:46 +01:00
|
|
|
)
|
2018-06-18 18:14:38 +02:00
|
|
|
|
2017-03-23 16:29:40 +01:00
|
|
|
return parser
|