From ca4e0613865a5f5d74ee0f82dfc031679e7b3115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 9 Oct 2025 20:59:06 +0200 Subject: [PATCH] [pp:exec] support '{_temppath}' replacement field (#8329) --- docs/configuration.rst | 4 ++-- gallery_dl/postprocessor/exec.py | 6 +++++- test/test_postprocessor.py | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index b215fb38..306ea928 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -7720,8 +7720,8 @@ Description name and any further elements its arguments. Each element of this list is evaluated as a `Format String`_ using - the files' metadata as well as ``{_path}``, ``{_directory}``, - and ``{_filename}``. + the files' metadata as well as + ``{_path}``, ``{_temppath}``, ``{_directory}``, and ``{_filename}``. exec.commands diff --git a/gallery_dl/postprocessor/exec.py b/gallery_dl/postprocessor/exec.py index ef11bff7..3b0ab22a 100644 --- a/gallery_dl/postprocessor/exec.py +++ b/gallery_dl/postprocessor/exec.py @@ -55,7 +55,8 @@ class ExecPP(PostProcessor): def _prepare_cmd(self, cmd): if isinstance(cmd, str): - self._sub = util.re(r"\{(_directory|_filename|_path|)\}").sub + self._sub = util.re( + r"\{(_directory|_filename|_(?:temp)?path|)\}").sub return self.exec_string, cmd else: return self.exec_list, [formatter.parse(arg) for arg in cmd] @@ -69,6 +70,7 @@ class ExecPP(PostProcessor): kwdict["_directory"] = pathfmt.realdirectory kwdict["_filename"] = pathfmt.filename + kwdict["_temppath"] = pathfmt.temppath kwdict["_path"] = pathfmt.realpath args = [arg.format_map(kwdict) for arg in self.args] @@ -131,6 +133,8 @@ class ExecPP(PostProcessor): return quote(self.pathfmt.realdirectory) if name == "_filename": return quote(self.pathfmt.filename) + if name == "_temppath": + return quote(self.pathfmt.temppath) return quote(self.pathfmt.realpath) diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index 17b36b62..5d52e1db 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -195,7 +195,8 @@ class ExecTest(BasePostprocessorTest): def test_command_string(self): self._create({ - "command": "echo {} {_path} {_directory} {_filename} && rm {};", + "command": "echo {} {_path} {_temppath} {_directory} {_filename} " + "&& rm {};", }) with patch("gallery_dl.util.Popen") as p: @@ -208,6 +209,7 @@ class ExecTest(BasePostprocessorTest): (f"echo " f"{self.pathfmt.realpath} " f"{self.pathfmt.realpath} " + f"{self.pathfmt.temppath} " f"{self.pathfmt.realdirectory} " f"{self.pathfmt.filename} " f"&& rm {self.pathfmt.realpath};"), @@ -243,7 +245,8 @@ class ExecTest(BasePostprocessorTest): def test_command_many(self): self._create({ "commands": [ - "echo {} {_path} {_directory} {_filename} && rm {};", + "echo {} {_path} {_temppath} {_directory} {_filename} " + "&& rm {};", ["~/script.sh", "{category}", "\fE _directory.upper()"], ] }) @@ -259,6 +262,7 @@ class ExecTest(BasePostprocessorTest): (f"echo " f"{self.pathfmt.realpath} " f"{self.pathfmt.realpath} " + f"{self.pathfmt.temppath} " f"{self.pathfmt.realdirectory} " f"{self.pathfmt.filename} " f"&& rm {self.pathfmt.realpath};"),