Skip to content

Commit

Permalink
Add "filtered" event to archive too
Browse files Browse the repository at this point in the history
  • Loading branch information
WyohKnott committed Jan 4, 2025
1 parent 31efa8b commit 298faf6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ Description
`archive <extractor.*.archive_>`__.

Available events are:
``file``, ``skip``
``file``, ``filtered``, ``skip``


extractor.*.archive-format
Expand Down
10 changes: 10 additions & 0 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, extr, parent=None):
if not extr:
raise exception.NoExtractorError()

self.archive = None
self.extractor = extr
self.pathfmt = None
self.status = 0
Expand Down Expand Up @@ -190,6 +191,7 @@ def run(self):
def dispatch(self, msg):
"""Call the appropriate message handler"""
hooks = self.hooks
archive = self.archive
pathfmt = self.pathfmt

if msg[0] == Message.Url:
Expand All @@ -203,6 +205,8 @@ def dispatch(self, msg):
if "filtered" in hooks:
for callback in hooks["filtered"]:
callback(pathfmt)
if archive and self._archive_write_filtered:
archive.add(kwdict)

elif msg[0] == Message.Directory:
self.update_kwdict(msg[1])
Expand All @@ -218,6 +222,8 @@ def dispatch(self, msg):
if "filtered" in hooks:
for callback in hooks["filtered"]:
callback(pathfmt)
if archive and self._archive_write_filtered:
archive.add(kwdict)

def handle_url(self, url, kwdict):
"""Handle Message.Url"""
Expand Down Expand Up @@ -596,11 +602,13 @@ def initialize(self, kwdict=None):
events = cfg("archive-event")
if events is None:
self._archive_write_file = True
self._archive_write_filtered = False
self._archive_write_skip = False
else:
if isinstance(events, str):
events = events.split(",")
self._archive_write_file = ("file" in events)
self._archive_write_filtered = ("filtered" in events)
self._archive_write_skip = ("skip" in events)

skip = cfg("skip", True)
Expand Down Expand Up @@ -728,6 +736,8 @@ def handle_url(self, url, kwdict):
self.extractor.sleep(self.sleep(), "download")
if self.archive and self._archive_write_skip:
self.archive.add(kwdict)
if self.archive and self._archive_write_filtered:
self.archive.add(kwdict)
self.out.skip(self.pathfmt.build_filename(kwdict))

def handle_directory(self, kwdict):
Expand Down

0 comments on commit 298faf6

Please sign in to comment.