From 5da200945b468cfae9099a9c4baa2e76c76a304b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 5 Dec 2025 16:40:23 +0100 Subject: [PATCH] implement 'post-filter' & 'post-range' options (#8643) --- docs/configuration.rst | 26 ++++++++++++++++++++++++-- docs/gallery-dl.conf | 2 ++ docs/options.md | 10 ++++++---- gallery_dl/job.py | 17 +++++++++++++++-- gallery_dl/option.py | 18 ++++++++++++++---- 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 0f313d03..0176f2ca 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1455,13 +1455,22 @@ Note The index of the first file is ``1``. +extractor.*.post-range +---------------------- +Type + ``string`` +Description + Like `image-range `__, + but for posts. + + extractor.*.chapter-range ------------------------- Type ``string`` Description Like `image-range `__, - but applies to delegated URLs like manga chapters, etc. + but for child extractors handling manga chapters, external URLs, etc. extractor.*.image-filter @@ -1480,6 +1489,19 @@ Description Available values are the filename-specific ones listed by ``-K`` or ``-j``. +extractor.*.post-filter +----------------------- +Type + * Condition_ + * ``list`` of Conditions_ +Example + * ``"post['id'] > 12345"`` + * ``["date >= datetime(2025, 5, 1)", "print(post_id)"]`` +Description + Like `image-filter `__, + but for posts. + + extractor.*.chapter-filter -------------------------- Type @@ -1490,7 +1512,7 @@ Example * ``["language == 'French'", "10 <= chapter < 20"]`` Description Like `image-filter `__, - but applies to delegated URLs like manga chapters, etc. + but for child extractors handling manga chapters, external URLs, etc. extractor.*.image-unique diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 03c9a09f..ba85e933 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -47,6 +47,8 @@ "image-filter" : null, "image-range" : null, "image-unique" : false, + "post-filter" : null, + "post-range" : null, "chapter-filter": null, "chapter-range" : null, "chapter-unique": false, diff --git a/docs/options.md b/docs/options.md index 7374bc04..f49aa029 100644 --- a/docs/options.md +++ b/docs/options.md @@ -145,16 +145,18 @@ --range RANGE Index range(s) specifying which files to download. These can be either a constant value, range, or slice (e.g. '5', '8-20', or '1:24:3') - --chapter-range RANGE Like '--range', but applies to manga chapters - and other delegated URLs + --post-range RANGE Like '--range', but for posts + --chapter-range RANGE Like '--range', but for child extractors + handling manga chapters, external URLs, etc. --filter EXPR Python expression controlling which files to download. Files for which the expression evaluates to False are ignored. Available keys are the filename-specific ones listed by '-K'. Example: --filter "image_width >= 1000 and rating in ('s', 'q')" - --chapter-filter EXPR Like '--filter', but applies to manga chapters - and other delegated URLs + --post-filter EXPR Like '--filter', but for posts + --chapter-filter EXPR Like '--filter', but for child extractors + handling manga chapters, external URLs, etc. ## Post-processing Options: -P, --postprocessor NAME Activate the specified post processor diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 39ff07cb..6e21762f 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -204,9 +204,12 @@ class Job(): def dispatch(self, messages): """Call the appropriate message handler""" msg = None + process = True for msg in messages: if msg[0] == Message.Url: + if process is None: + continue _, url, kwdict = msg if self.metadata_url: kwdict[self.metadata_url] = url @@ -217,10 +220,19 @@ class Job(): FLAGS.process("FILE") elif msg[0] == Message.Directory: - self.update_kwdict(msg[1]) - self.handle_directory(msg[1]) + kwdict = msg[1] + if self.pred_post("", kwdict): + process = True + self.update_kwdict(kwdict) + self.handle_directory(kwdict) + else: + process = None + if FLAGS.POST is not None: + FLAGS.process("POST") elif msg[0] == Message.Queue: + if process is None: + continue _, url, kwdict = msg if self.metadata_url: kwdict[self.metadata_url] = url @@ -262,6 +274,7 @@ class Job(): def _init(self): self.extractor.initialize() self.pred_url = self._prepare_predicates("image", True) + self.pred_post = self._prepare_predicates("post", False) self.pred_queue = self._prepare_predicates("chapter", False) def _prepare_predicates(self, target, skip=True): diff --git a/gallery_dl/option.py b/gallery_dl/option.py index 05cc9d35..a47d8cd1 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -697,11 +697,16 @@ def build_parser(): "These can be either a constant value, range, or slice " "(e.g. '5', '8-20', or '1:24:3')"), ) + selection.add_argument( + "--post-range", + dest="post-range", metavar="RANGE", action=ConfigAction, + help=("Like '--range', but for posts"), + ) selection.add_argument( "--chapter-range", dest="chapter-range", metavar="RANGE", action=ConfigAction, - help=("Like '--range', but applies to manga chapters " - "and other delegated URLs"), + help=("Like '--range', but for child extractors handling " + "manga chapters, external URLs, etc."), ) selection.add_argument( "--filter", @@ -712,11 +717,16 @@ def build_parser(): "Example: --filter \"image_width >= 1000 and " "rating in ('s', 'q')\""), ) + selection.add_argument( + "--post-filter", + dest="post-filter", metavar="EXPR", action=ConfigAction, + help=("Like '--filter', but for posts"), + ) selection.add_argument( "--chapter-filter", dest="chapter-filter", metavar="EXPR", action=ConfigAction, - help=("Like '--filter', but applies to manga chapters " - "and other delegated URLs"), + help=("Like '--filter', but for child extractors handling " + "manga chapters, external URLs, etc."), ) infojson = {