mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-21 18:22:30 +01:00
add '--print' and '--print-to-file' command-line options
This commit is contained in:
parent
2e1dab3036
commit
10c56a561d
@ -48,6 +48,11 @@
|
||||
-K, --list-keywords Print a list of available keywords and example
|
||||
values for the given URLs
|
||||
-e, --error-file FILE Add input URLs which returned an error to FILE
|
||||
-N, --print [EVENT:]FORMAT Write FORMAT during EVENT (default 'prepare') to
|
||||
standard output. Examples: 'id' or
|
||||
'post:{md5[:8]}'
|
||||
--print-to-file [EVENT:]FORMAT FILE
|
||||
Append FORMAT during EVENT to FILE
|
||||
--list-modules Print a list of available extractor modules
|
||||
--list-extractors CATEGORIES
|
||||
Print a list of extractor classes with
|
||||
@ -153,7 +158,7 @@
|
||||
current filename format to FORMAT
|
||||
--ugoira FMT Convert Pixiv Ugoira to FMT using FFmpeg.
|
||||
Supported formats are 'webm', 'mp4', 'gif',
|
||||
'vp8', 'vp9', 'vp9-lossless', 'copy'.
|
||||
'vp8', 'vp9', 'vp9-lossless', 'copy', 'zip'.
|
||||
--exec CMD Execute CMD for each downloaded file. Supported
|
||||
replacement fields are {} or {_path},
|
||||
{_directory}, {_filename}. Example: --exec
|
||||
|
@ -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):
|
||||
@ -342,6 +386,19 @@ def build_parser():
|
||||
dest="errorfile", metavar="FILE", action=ConfigAction,
|
||||
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",
|
||||
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user