diff options
Diffstat (limited to 'gallery_dl/postprocessor')
| -rw-r--r-- | gallery_dl/postprocessor/common.py | 4 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/metadata.py | 9 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/python.py | 20 |
3 files changed, 25 insertions, 8 deletions
diff --git a/gallery_dl/postprocessor/common.py b/gallery_dl/postprocessor/common.py index 8da8417..9992c56 100644 --- a/gallery_dl/postprocessor/common.py +++ b/gallery_dl/postprocessor/common.py @@ -54,7 +54,11 @@ class PostProcessor(): else: self.log.debug( "Using %s archive '%s'", self.name, archive_path) + job.register_hooks({"finalize": self._close_archive}) return True self.archive = None return False + + def _close_archive(self, _): + self.archive.close() diff --git a/gallery_dl/postprocessor/metadata.py b/gallery_dl/postprocessor/metadata.py index c74f92f..a6d2b7f 100644 --- a/gallery_dl/postprocessor/metadata.py +++ b/gallery_dl/postprocessor/metadata.py @@ -45,6 +45,15 @@ class MetadataPP(PostProcessor): cfmt = "\n".join(cfmt) + "\n" self._content_fmt = formatter.parse(cfmt).format_map ext = "txt" + elif mode == "print": + nl = "\n" + if isinstance(cfmt, list): + cfmt = f"{nl.join(cfmt)}{nl}" + if cfmt[-1] != nl and (cfmt[0] != "\f" or cfmt[1] == "F"): + cfmt = f"{cfmt}{nl}" + self.write = self._write_custom + self._content_fmt = formatter.parse(cfmt).format_map + filename = "-" elif mode == "jsonl": self.write = self._write_json self._json_encode = self._make_encoder(options).encode diff --git a/gallery_dl/postprocessor/python.py b/gallery_dl/postprocessor/python.py index db71da2..66d9343 100644 --- a/gallery_dl/postprocessor/python.py +++ b/gallery_dl/postprocessor/python.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Mike Fährmann +# Copyright 2023-2025 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 @@ -17,13 +17,14 @@ class PythonPP(PostProcessor): def __init__(self, job, options): PostProcessor.__init__(self, job) - spec = options["function"] - module_name, _, function_name = spec.rpartition(":") - module = util.import_file(module_name) - self.function = getattr(module, function_name) - - if self._init_archive(job, options): - self.run = self.run_archive + mode = options.get("mode") + if mode == "eval" or not mode and options.get("expression"): + self.function = util.compile_expression(options["expression"]) + else: + spec = options["function"] + module_name, _, function_name = spec.rpartition(":") + module = util.import_file(module_name) + self.function = getattr(module, function_name) events = options.get("event") if events is None: @@ -32,6 +33,9 @@ class PythonPP(PostProcessor): events = events.split(",") job.register_hooks({event: self.run for event in events}, options) + if self._init_archive(job, options): + self.run = self.run_archive + def run(self, pathfmt): self.function(pathfmt.kwdict) |
