aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/option.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2024-10-25 17:27:30 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2024-10-25 17:27:30 -0400
commitfc004701f923bb954a22c7fec2ae8d607e78cb2b (patch)
treea5bea4ed6447ea43c099131430e3bd6182ee87d7 /gallery_dl/option.py
parent0db541f524e1774865efebcbe5653e9ad76ea2e8 (diff)
New upstream version 1.27.7.upstream/1.27.7
Diffstat (limited to 'gallery_dl/option.py')
-rw-r--r--gallery_dl/option.py59
1 files changed, 58 insertions, 1 deletions
diff --git a/gallery_dl/option.py b/gallery_dl/option.py
index c4f5b94..b38ad74 100644
--- a/gallery_dl/option.py
+++ b/gallery_dl/option.py
@@ -10,6 +10,7 @@
import argparse
import logging
+import os.path
import sys
from . import job, util, version
@@ -152,6 +153,49 @@ class UgoiraAction(argparse.Action):
namespace.postprocessors.append(pp)
+class PrintAction(argparse.Action):
+ def __call__(self, parser, namespace, value, option_string=None):
+ if self.const:
+ filename = self.const
+ base = None
+ mode = "w"
+ else:
+ value, path = value
+ base, filename = os.path.split(path)
+ mode = "a"
+
+ event, sep, format_string = value.partition(":")
+ if not sep:
+ format_string = event
+ event = ("prepare",)
+ else:
+ event = event.strip().lower()
+ if event not in {"init", "file", "after", "skip", "error",
+ "prepare", "prepare-after", "post", "post-after",
+ "finalize", "finalize-success", "finalize-error"}:
+ format_string = value
+ event = ("prepare",)
+
+ if not format_string:
+ return
+
+ if "{" not in format_string and \
+ " " not in format_string and \
+ format_string[0] != "\f":
+ format_string = "{" + format_string + "}"
+ if format_string[-1] != "\n":
+ format_string += "\n"
+
+ namespace.postprocessors.append({
+ "name" : "metadata",
+ "event" : event,
+ "filename" : filename,
+ "base-directory": base or ".",
+ "content-format": format_string,
+ "open" : mode,
+ })
+
+
class Formatter(argparse.HelpFormatter):
"""Custom HelpFormatter class to customize help output"""
def __init__(self, prog):
@@ -343,6 +387,19 @@ def build_parser():
help="Add input URLs which returned an error to FILE",
)
output.add_argument(
+ "-N", "--print",
+ dest="postprocessors", metavar="[EVENT:]FORMAT",
+ action=PrintAction, const="-", default=[],
+ help=("Write FORMAT during EVENT (default 'prepare') to standard "
+ "output. Examples: 'id' or 'post:{md5[:8]}'"),
+ )
+ output.add_argument(
+ "--print-to-file",
+ dest="postprocessors", metavar="[EVENT:]FORMAT FILE",
+ action=PrintAction, nargs=2,
+ help="Append FORMAT during EVENT to FILE",
+ )
+ output.add_argument(
"--list-modules",
dest="list_modules", action="store_true",
help="Print a list of available extractor modules",
@@ -616,7 +673,7 @@ def build_parser():
postprocessor = parser.add_argument_group("Post-processing Options")
postprocessor.add_argument(
"-P", "--postprocessor",
- dest="postprocessors", metavar="NAME", action="append", default=[],
+ dest="postprocessors", metavar="NAME", action="append",
help="Activate the specified post processor",
)
postprocessor.add_argument(