diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 57d7d0c2..186e79e9 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -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) diff --git a/gallery_dl/util.py b/gallery_dl/util.py index fca3e665..fe9a9e78 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -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