[util] set flags in range predicates

use flags to stop extractors immediately when hitting the upper range
limit instead of raising an exception one predicate check later
This commit is contained in:
Mike Fährmann
2026-02-02 21:48:45 +01:00
parent e44c5bd707
commit 0c04090ff4
2 changed files with 27 additions and 11 deletions

View File

@@ -300,7 +300,8 @@ class Job():
alt is not None and (prange := extr.config(alt + "-range")):
try:
skip = extr.skip if skip and not pfilter else None
predicates.append(util.predicate_range(prange, skip))
flag = target if alt is not None else None
predicates.append(util.predicate_range(prange, skip, flag))
except ValueError as exc:
extr.log.warning("invalid %s range: %s", target, exc)

View File

@@ -997,7 +997,7 @@ def predicate_filter(expr, target="image"):
return _pred
def predicate_range(ranges, skip=None):
def predicate_range(ranges, skip=None, flag=None):
"""Predicate; True if the current index is in the given range(s)"""
if ranges := predicate_range_parse(ranges):
# technically wrong for 'step > 2', but good enough for now
@@ -1009,17 +1009,32 @@ def predicate_range(ranges, skip=None):
else:
index = upper = 0
def _pred(_url, _kwdict):
nonlocal index
if flag is None:
def _pred(_url, _kwdict):
nonlocal index
if index >= upper:
raise exception.StopExtraction()
index += 1
if index >= upper:
raise exception.StopExtraction()
index += 1
for range in ranges:
if index in range:
return True
return False
for range in ranges:
if index in range:
return True
return False
else:
def _pred(_url, _kwdict):
nonlocal index
index += 1
if index >= upper:
if index > upper:
raise exception.StopExtraction()
FLAGS.__dict__[flag.upper()] = "stop"
for range in ranges:
if index in range:
return True
return False
return _pred