aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/postprocessor/python.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2025-09-23 07:44:37 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2025-09-23 07:44:37 -0400
commit42b62671fabfdcf983a9575221420d85f7fbcac1 (patch)
treefa6b2af249a7216aae5c70a926c6d08be1ac55a6 /gallery_dl/postprocessor/python.py
parent3b7f8716690b7aa1994a9cb387bbc7215e01a4ed (diff)
New upstream version 1.30.8.upstream/1.30.8
Diffstat (limited to 'gallery_dl/postprocessor/python.py')
-rw-r--r--gallery_dl/postprocessor/python.py20
1 files changed, 12 insertions, 8 deletions
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)