From 60b655429f048f18e44c26fc365576bb0673bd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 30 Aug 2024 18:22:46 +0200 Subject: [PATCH] add '--rename' and '--rename-to' command-line options (#5846, #6044) --- docs/options.md | 7 ++++++- gallery_dl/option.py | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/docs/options.md b/docs/options.md index 7eee73bd..81a363c2 100644 --- a/docs/options.md +++ b/docs/options.md @@ -146,7 +146,12 @@ --mtime NAME Set file modification times according to metadata selected by NAME. Examples: 'date' or 'status[date]' - --ugoira FORMAT Convert Pixiv Ugoira to FORMAT using FFmpeg. + --rename FORMAT Rename previously downloaded files from FORMAT + to the current filename format + --rename-to FORMAT Rename previously downloaded files from the + current filename format to FORMAT (disables + downloads) + --ugoira FMT Convert Pixiv Ugoira to FMT using FFmpeg. Supported formats are 'webm', 'mp4', 'gif', 'vp8', 'vp9', 'vp9-lossless', 'copy'. --exec CMD Execute CMD for each downloaded file. Supported diff --git a/gallery_dl/option.py b/gallery_dl/option.py index f33ecf5f..9b51b403 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -74,6 +74,22 @@ class MtimeAction(argparse.Action): }) +class RenameAction(argparse.Action): + """Configure rename post processors""" + def __call__(self, parser, namespace, value, option_string=None): + if self.const: + namespace.options.append(((), "download", False)) + namespace.postprocessors.append({ + "name": "rename", + "to" : value, + }) + else: + namespace.postprocessors.append({ + "name": "rename", + "from": value, + }) + + class UgoiraAction(argparse.Action): """Configure ugoira post processors""" def __call__(self, parser, namespace, value, option_string=None): @@ -661,10 +677,22 @@ def build_parser(): const="date|status[date]", help=argparse.SUPPRESS, ) + postprocessor.add_argument( + "--rename", + dest="postprocessors", metavar="FORMAT", action=RenameAction, const=0, + help=("Rename previously downloaded files from FORMAT " + "to the current filename format"), + ) + postprocessor.add_argument( + "--rename-to", + dest="postprocessors", metavar="FORMAT", action=RenameAction, const=1, + help=("Rename previously downloaded files from the current filename " + "format to FORMAT (disables downloads)"), + ) postprocessor.add_argument( "--ugoira", - dest="postprocessors", metavar="FORMAT", action=UgoiraAction, - help=("Convert Pixiv Ugoira to FORMAT using FFmpeg. " + dest="postprocessors", metavar="FMT", action=UgoiraAction, + help=("Convert Pixiv Ugoira to FMT using FFmpeg. " "Supported formats are 'webm', 'mp4', 'gif', " "'vp8', 'vp9', 'vp9-lossless', 'copy'."), )