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``.
extractor.*.post-range
----------------------
Type
``string``
Description
Like `image-range <extractor.*.image-range_>`__,
but for posts.
extractor.*.chapter-range
-------------------------
Type
``string``
Description
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
@@ -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 <extractor.*.image-filter_>`__,
but for posts.
extractor.*.chapter-filter
--------------------------
Type
@@ -1490,7 +1512,7 @@ Example
* ``["language == 'French'", "10 <= chapter < 20"]``
Description
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

View File

@@ -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,

View File

@@ -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

View File

@@ -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):

View File

@@ -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 = {