implement 'post-filter' & 'post-range' options

(#8643)
This commit is contained in:
Mike Fährmann
2025-12-05 16:40:23 +01:00
parent d9c1d15aee
commit 5da200945b
5 changed files with 61 additions and 12 deletions

View File

@@ -1455,13 +1455,22 @@ Note
The index of the first file is ``1``. The index of the first file is ``1``.
extractor.*.post-range
----------------------
Type
``string``
Description
Like `image-range <extractor.*.image-range_>`__,
but for posts.
extractor.*.chapter-range extractor.*.chapter-range
------------------------- -------------------------
Type Type
``string`` ``string``
Description Description
Like `image-range <extractor.*.image-range_>`__, Like `image-range <extractor.*.image-range_>`__,
but applies to delegated URLs like manga chapters, etc. but for child extractors handling manga chapters, external URLs, etc.
extractor.*.image-filter extractor.*.image-filter
@@ -1480,6 +1489,19 @@ Description
Available values are the filename-specific ones listed by ``-K`` or ``-j``. 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 <extractor.*.image-filter_>`__,
but for posts.
extractor.*.chapter-filter extractor.*.chapter-filter
-------------------------- --------------------------
Type Type
@@ -1490,7 +1512,7 @@ Example
* ``["language == 'French'", "10 <= chapter < 20"]`` * ``["language == 'French'", "10 <= chapter < 20"]``
Description Description
Like `image-filter <extractor.*.image-filter_>`__, Like `image-filter <extractor.*.image-filter_>`__,
but applies to delegated URLs like manga chapters, etc. but for child extractors handling manga chapters, external URLs, etc.
extractor.*.image-unique extractor.*.image-unique

View File

@@ -47,6 +47,8 @@
"image-filter" : null, "image-filter" : null,
"image-range" : null, "image-range" : null,
"image-unique" : false, "image-unique" : false,
"post-filter" : null,
"post-range" : null,
"chapter-filter": null, "chapter-filter": null,
"chapter-range" : null, "chapter-range" : null,
"chapter-unique": false, "chapter-unique": false,

View File

@@ -145,16 +145,18 @@
--range RANGE Index range(s) specifying which files to --range RANGE Index range(s) specifying which files to
download. These can be either a constant value, download. These can be either a constant value,
range, or slice (e.g. '5', '8-20', or '1:24:3') range, or slice (e.g. '5', '8-20', or '1:24:3')
--chapter-range RANGE Like '--range', but applies to manga chapters --post-range RANGE Like '--range', but for posts
and other delegated URLs --chapter-range RANGE Like '--range', but for child extractors
handling manga chapters, external URLs, etc.
--filter EXPR Python expression controlling which files to --filter EXPR Python expression controlling which files to
download. Files for which the expression download. Files for which the expression
evaluates to False are ignored. Available keys evaluates to False are ignored. Available keys
are the filename-specific ones listed by '-K'. are the filename-specific ones listed by '-K'.
Example: --filter "image_width >= 1000 and Example: --filter "image_width >= 1000 and
rating in ('s', 'q')" rating in ('s', 'q')"
--chapter-filter EXPR Like '--filter', but applies to manga chapters --post-filter EXPR Like '--filter', but for posts
and other delegated URLs --chapter-filter EXPR Like '--filter', but for child extractors
handling manga chapters, external URLs, etc.
## Post-processing Options: ## Post-processing Options:
-P, --postprocessor NAME Activate the specified post processor -P, --postprocessor NAME Activate the specified post processor

View File

@@ -204,9 +204,12 @@ class Job():
def dispatch(self, messages): def dispatch(self, messages):
"""Call the appropriate message handler""" """Call the appropriate message handler"""
msg = None msg = None
process = True
for msg in messages: for msg in messages:
if msg[0] == Message.Url: if msg[0] == Message.Url:
if process is None:
continue
_, url, kwdict = msg _, url, kwdict = msg
if self.metadata_url: if self.metadata_url:
kwdict[self.metadata_url] = url kwdict[self.metadata_url] = url
@@ -217,10 +220,19 @@ class Job():
FLAGS.process("FILE") FLAGS.process("FILE")
elif msg[0] == Message.Directory: elif msg[0] == Message.Directory:
self.update_kwdict(msg[1]) kwdict = msg[1]
self.handle_directory(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: elif msg[0] == Message.Queue:
if process is None:
continue
_, url, kwdict = msg _, url, kwdict = msg
if self.metadata_url: if self.metadata_url:
kwdict[self.metadata_url] = url kwdict[self.metadata_url] = url
@@ -262,6 +274,7 @@ class Job():
def _init(self): def _init(self):
self.extractor.initialize() self.extractor.initialize()
self.pred_url = self._prepare_predicates("image", True) self.pred_url = self._prepare_predicates("image", True)
self.pred_post = self._prepare_predicates("post", False)
self.pred_queue = self._prepare_predicates("chapter", False) self.pred_queue = self._prepare_predicates("chapter", False)
def _prepare_predicates(self, target, skip=True): def _prepare_predicates(self, target, skip=True):

View File

@@ -697,11 +697,16 @@ def build_parser():
"These can be either a constant value, range, or slice " "These can be either a constant value, range, or slice "
"(e.g. '5', '8-20', or '1:24:3')"), "(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( selection.add_argument(
"--chapter-range", "--chapter-range",
dest="chapter-range", metavar="RANGE", action=ConfigAction, dest="chapter-range", metavar="RANGE", action=ConfigAction,
help=("Like '--range', but applies to manga chapters " help=("Like '--range', but for child extractors handling "
"and other delegated URLs"), "manga chapters, external URLs, etc."),
) )
selection.add_argument( selection.add_argument(
"--filter", "--filter",
@@ -712,11 +717,16 @@ def build_parser():
"Example: --filter \"image_width >= 1000 and " "Example: --filter \"image_width >= 1000 and "
"rating in ('s', 'q')\""), "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( selection.add_argument(
"--chapter-filter", "--chapter-filter",
dest="chapter-filter", metavar="EXPR", action=ConfigAction, dest="chapter-filter", metavar="EXPR", action=ConfigAction,
help=("Like '--filter', but applies to manga chapters " help=("Like '--filter', but for child extractors handling "
"and other delegated URLs"), "manga chapters, external URLs, etc."),
) )
infojson = { infojson = {