From c12a97bcdeb644d5147c26ce0c1ac52139388b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 31 Oct 2022 14:35:48 +0100 Subject: [PATCH] [postprocessor] add 'post-after' event (#3117) --- docs/configuration.rst | 2 ++ gallery_dl/job.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index fa076227..546f45b0 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3653,6 +3653,8 @@ Description ``post`` When starting to download all files of a `post`, e.g. a Tweet on Twitter or a post on Patreon. + ``post-after`` + After downloading all files of a `post` metadata.fields diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 0cf419f4..5fe6dfbb 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -283,6 +283,9 @@ class DownloadJob(Job): if not self.pathfmt: self.initialize(kwdict) else: + if "post-after" in self.hooks: + for callback in self.hooks["post-after"]: + callback(self.pathfmt) self.pathfmt.set_directory(kwdict) if "post" in self.hooks: for callback in self.hooks["post"]: @@ -337,14 +340,20 @@ class DownloadJob(Job): self._write_unsupported(url) def handle_finalize(self): - pathfmt = self.pathfmt if self.archive: self.archive.close() + + pathfmt = self.pathfmt if pathfmt: + hooks = self.hooks + if "post-after" in hooks: + for callback in hooks["post-after"]: + callback(pathfmt) + self.extractor._store_cookies() - if "finalize" in self.hooks: + if "finalize" in hooks: status = self.status - for callback in self.hooks["finalize"]: + for callback in hooks["finalize"]: callback(pathfmt, status) def handle_skip(self):