Skip to content

Commit

Permalink
add 'skip-filter' option (#5255)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 10, 2024
1 parent fd734b9 commit d2f50ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ Description
filename extension (``file.1.ext``, ``file.2.ext``, etc.)


extractor.*.skip-filter
-----------------------
Type
``string``
Description
Python expression controlling which skipped files to count towards
``"abort"`` / ``"terminate"`` / ``"exit"``.


extractor.*.sleep
-----------------
Type
Expand Down
15 changes: 12 additions & 3 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,12 @@ def handle_skip(self):
for callback in self.hooks["skip"]:
callback(pathfmt)
if self._skipexc:
self._skipcnt += 1
if self._skipcnt >= self._skipmax:
raise self._skipexc()
if not self._skipftr or self._skipftr(pathfmt.kwdict):
self._skipcnt += 1
if self._skipcnt >= self._skipmax:
raise self._skipexc()
else:
self._skipcnt = 0

def download(self, url):
"""Download 'url'"""
Expand Down Expand Up @@ -559,6 +562,12 @@ def initialize(self, kwdict=None):
elif skip == "exit":
self._skipexc = SystemExit
self._skipmax = text.parse_int(smax)

skip_filter = cfg("skip-filter")
if skip_filter:
self._skipftr = util.compile_expression(skip_filter)
else:
self._skipftr = None
else:
# monkey-patch methods to always return False
pathfmt.exists = lambda x=None: False
Expand Down

0 comments on commit d2f50ec

Please sign in to comment.