Skip to content

Commit

Permalink
Add a "filtered" event
Browse files Browse the repository at this point in the history
Add a filtered event to apply postprocessing (python/metadata) to posts
that have been excluded from download by the filtering rules
(image and chapter filters).

The goal is to do analysis on filtered content in order to feed a blacklist.
  • Loading branch information
WyohKnott committed Dec 30, 2024
1 parent 7391dd2 commit 6e76140
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6327,6 +6327,9 @@ Description
``prepare-after``
Before a file download,
but after building and checking file paths
``filtered``
When a file has been excluded from download
by image-filter or chapter-filter
``file``
When completing a file download,
but before it gets moved to its target location
Expand Down
12 changes: 12 additions & 0 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, extr, parent=None):
self.extractor = extr
self.pathfmt = None
self.status = 0
self.hooks = ()
self.kwdict = {}
self.kwdict_eval = False

Expand Down Expand Up @@ -188,13 +189,20 @@ def run(self):

def dispatch(self, msg):
"""Call the appropriate message handler"""
hooks = self.hooks
pathfmt = self.pathfmt

if msg[0] == Message.Url:
_, url, kwdict = msg
if self.metadata_url:
kwdict[self.metadata_url] = url
if self.pred_url(url, kwdict):
self.update_kwdict(kwdict)
self.handle_url(url, kwdict)
else:
if "filtered" in hooks:
for callback in hooks["filtered"]:
callback(pathfmt)

elif msg[0] == Message.Directory:
self.update_kwdict(msg[1])
Expand All @@ -206,6 +214,10 @@ def dispatch(self, msg):
kwdict[self.metadata_url] = url
if self.pred_queue(url, kwdict):
self.handle_queue(url, kwdict)
else:
if "filtered" in hooks:
for callback in hooks["filtered"]:
callback(pathfmt)

def handle_url(self, url, kwdict):
"""Handle Message.Url"""
Expand Down
5 changes: 3 additions & 2 deletions gallery_dl/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def __call__(self, parser, namespace, value, option_string=None):
else:
event = event.strip().lower()
if event not in {"init", "file", "after", "skip", "error",
"prepare", "prepare-after", "post", "post-after",
"finalize", "finalize-success", "finalize-error"}:
"prepare", "prepare-after", "filtered", "post",
"post-after", "finalize", "finalize-success",
"finalize-error"}:
format_string = value
event = ("prepare",)

Expand Down

0 comments on commit 6e76140

Please sign in to comment.