From 168331d147715a5a306bd7adf043382ad6442e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 16 Nov 2023 17:15:17 +0100 Subject: [PATCH] replace '--ugoira-conv' etc with a general '--ugoira' update --ugoira webm to use the same FFmpeg args as Danbooru --ugoira-conv -> --ugoira vp8 --ugoira-conv-lossless -> --ugoira vp9-lossless --ugoira-conv-copy -> --ugoira copy (--ugoira-conv and co still work as before, but --help now lists only --ugoira) --- docs/options.md | 8 ++-- gallery_dl/option.py | 98 +++++++++++++++++++++++++++++++++----------- 2 files changed, 76 insertions(+), 30 deletions(-) diff --git a/docs/options.md b/docs/options.md index 270a9f0b..f70e766d 100644 --- a/docs/options.md +++ b/docs/options.md @@ -120,11 +120,9 @@ ## Post-processing Options: --zip Store downloaded files in a ZIP archive --cbz Store downloaded files in a CBZ archive - --ugoira-conv Convert Pixiv Ugoira to WebM (requires FFmpeg) - --ugoira-conv-lossless Convert Pixiv Ugoira to WebM in VP9 lossless - mode - --ugoira-conv-copy Convert Pixiv Ugoira to MKV without re-encoding - any frames + --ugoira FORMAT Convert Pixiv Ugoira to FORMAT using FFmpeg. + Supported formats are 'webm', 'mp4', 'gif', + 'vp8', 'vp9', 'vp9-lossless', 'copy'. --write-metadata Write metadata to separate JSON files --write-info-json Write gallery metadata to a info.json file --write-tags Write image tags to separate text files diff --git a/gallery_dl/option.py b/gallery_dl/option.py index aa42400d..209452fe 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -66,7 +66,7 @@ class InputfileAction(argparse.Action): class MtimeAction(argparse.Action): - """Configure mtime post processor""" + """Configure mtime post processors""" def __call__(self, parser, namespace, value, option_string=None): namespace.postprocessors.append({ "name": "mtime", @@ -74,6 +74,64 @@ class MtimeAction(argparse.Action): }) +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) + + class Formatter(argparse.HelpFormatter): """Custom HelpFormatter class to customize help output""" def __init__(self, prog): @@ -487,38 +545,28 @@ def build_parser(): }, help="Store downloaded files in a CBZ archive", ) + 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", action="append_const", const={ - "name" : "ugoira", - "ffmpeg-args" : ("-c:v", "libvpx", "-crf", "4", "-b:v", "5000k"), - "ffmpeg-twopass": True, - "whitelist" : ("pixiv", "danbooru"), - }, - help="Convert Pixiv Ugoira to WebM (requires FFmpeg)", + dest="postprocessors", nargs=0, action=UgoiraAction, const="vp8", + help=argparse.SUPPRESS, ) 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", + dest="postprocessors", nargs=0, action=UgoiraAction, + const="vp9-lossless", + help=argparse.SUPPRESS, ) postprocessor.add_argument( "--ugoira-conv-copy", - dest="postprocessors", action="append_const", const={ - "name" : "ugoira", - "extension" : "mkv", - "ffmpeg-args" : ("-c:v", "copy"), - "ffmpeg-twopass" : False, - "repeat-last-frame": False, - "whitelist" : ("pixiv", "danbooru"), - }, - help="Convert Pixiv Ugoira to MKV without re-encoding any frames", + dest="postprocessors", nargs=0, action=UgoiraAction, const="copy", + help=argparse.SUPPRESS, ) postprocessor.add_argument( "--write-metadata",