diff options
| author | 2024-12-02 00:31:59 -0500 | |
|---|---|---|
| committer | 2024-12-02 00:31:59 -0500 | |
| commit | 1981ccaaea6eab2cf32536ec5afe132a870914d8 (patch) | |
| tree | 013f1e17d922d3a6abf7f57aa6a175c2ce5d93bc /gallery_dl/postprocessor | |
| parent | fc004701f923bb954a22c7fec2ae8d607e78cb2b (diff) | |
New upstream version 1.28.0.upstream/1.28.0
Diffstat (limited to 'gallery_dl/postprocessor')
| -rw-r--r-- | gallery_dl/postprocessor/classify.py | 47 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/common.py | 22 |
2 files changed, 38 insertions, 31 deletions
diff --git a/gallery_dl/postprocessor/classify.py b/gallery_dl/postprocessor/classify.py index 34af1d9..5642955 100644 --- a/gallery_dl/postprocessor/classify.py +++ b/gallery_dl/postprocessor/classify.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2018-2021 Mike Fährmann +# Copyright 2018-2024 Mike Fährmann # # 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 @@ -15,44 +15,43 @@ import os class ClassifyPP(PostProcessor): DEFAULT_MAPPING = { - "Music" : ("mp3", "aac", "flac", "ogg", "wma", "m4a", "wav"), - "Video" : ("flv", "ogv", "avi", "mp4", "mpg", "mpeg", "3gp", "mkv", - "webm", "vob", "wmv"), - "Pictures" : ("jpg", "jpeg", "png", "gif", "bmp", "svg", "webp"), + "Pictures" : ("jpg", "jpeg", "png", "gif", "bmp", "svg", "webp", + "avif", "heic", "heif", "ico", "psd"), + "Video" : ("flv", "ogv", "avi", "mp4", "mpg", "mpeg", "3gp", "mkv", + "webm", "vob", "wmv", "m4v", "mov"), + "Music" : ("mp3", "aac", "flac", "ogg", "wma", "m4a", "wav"), "Archives" : ("zip", "rar", "7z", "tar", "gz", "bz2"), + "Documents": ("txt", "pdf"), } def __init__(self, job, options): PostProcessor.__init__(self, job) - mapping = options.get("mapping", self.DEFAULT_MAPPING) + self.directory = self.realdirectory = "" + mapping = options.get("mapping", self.DEFAULT_MAPPING) self.mapping = { ext: directory for directory, exts in mapping.items() for ext in exts } - job.register_hooks( - {"prepare": self.prepare, "file": self.move}, options) - def prepare(self, pathfmt): - ext = pathfmt.extension - if ext in self.mapping: - # set initial paths to enable download skips - self._build_paths(pathfmt, self.mapping[ext]) + job.register_hooks({ + "post" : self.initialize, + "prepare": self.prepare, + }, options) + + def initialize(self, pathfmt): + # store base directory paths + self.directory = pathfmt.directory + self.realdirectory = pathfmt.realdirectory - def move(self, pathfmt): + def prepare(self, pathfmt): + # extend directory paths depending on file extension ext = pathfmt.extension if ext in self.mapping: - # rebuild paths in case the filename extension changed - path = self._build_paths(pathfmt, self.mapping[ext]) - os.makedirs(path, exist_ok=True) - - @staticmethod - def _build_paths(pathfmt, extra): - path = pathfmt.realdirectory + extra - pathfmt.realpath = path + os.sep + pathfmt.filename - pathfmt.path = pathfmt.directory + extra + os.sep + pathfmt.filename - return path + extra = self.mapping[ext] + os.sep + pathfmt.directory = self.directory + extra + pathfmt.realdirectory = self.realdirectory + extra __postprocessor__ = ClassifyPP diff --git a/gallery_dl/postprocessor/common.py b/gallery_dl/postprocessor/common.py index d4e1603..a9143a6 100644 --- a/gallery_dl/postprocessor/common.py +++ b/gallery_dl/postprocessor/common.py @@ -26,19 +26,27 @@ class PostProcessor(): if archive_path: extr = job.extractor archive_path = util.expand_path(archive_path) - if not prefix: - prefix = "_" + self.name.upper() + "_" - archive_format = ( - options.get("archive-prefix", extr.category) + - options.get("archive-format", prefix + extr.archive_fmt)) + + archive_prefix = options.get("archive-prefix") + if archive_prefix is None: + archive_prefix = extr.category + + archive_format = options.get("archive-format") + if archive_format is None: + if prefix is None: + prefix = "_" + self.name.upper() + "_" + archive_format = prefix + extr.archive_fmt + try: if "{" in archive_path: archive_path = formatter.parse(archive_path).format_map( job.pathfmt.kwdict) self.archive = archive.DownloadArchive( - archive_path, archive_format, + archive_path, + archive_prefix + archive_format, options.get("archive-pragma"), - "_archive_" + self.name) + "_archive_" + self.name, + ) except Exception as exc: self.log.warning( "Failed to open %s archive at '%s' (%s: %s)", |
