diff options
| author | 2023-10-03 18:32:03 -0400 | |
|---|---|---|
| committer | 2023-10-03 18:32:03 -0400 | |
| commit | 6b534bfa74884dccf734d306b250c05557f9311d (patch) | |
| tree | 0172eebcb36b3ca64030ce90ae5865f01172daf3 /gallery_dl/postprocessor/python.py | |
| parent | 25c6de611041ec1efba8e3120aaf9167e0d63fbb (diff) | |
| parent | b8758ecd073910ce3220b2e68399147b425c37b8 (diff) | |
Update upstream source from tag 'upstream/1.26.0'
Update to upstream version '1.26.0'
with Debian dir bf0b268cbba44da63b86fe28caaaef53198f3ea3
Diffstat (limited to 'gallery_dl/postprocessor/python.py')
| -rw-r--r-- | gallery_dl/postprocessor/python.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/gallery_dl/postprocessor/python.py b/gallery_dl/postprocessor/python.py new file mode 100644 index 0000000..db71da2 --- /dev/null +++ b/gallery_dl/postprocessor/python.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +# Copyright 2023 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 +# published by the Free Software Foundation. + +"""Run Python functions""" + +from .common import PostProcessor +from .. import util + + +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 + + events = options.get("event") + if events is None: + events = ("file",) + elif isinstance(events, str): + events = events.split(",") + job.register_hooks({event: self.run for event in events}, options) + + def run(self, pathfmt): + self.function(pathfmt.kwdict) + + def run_archive(self, pathfmt): + kwdict = pathfmt.kwdict + if self.archive.check(kwdict): + return + self.function(kwdict) + self.archive.add(kwdict) + + +__postprocessor__ = PythonPP |
