diff --git a/gallery_dl/job.py b/gallery_dl/job.py index c424a53045..418cedb2d2 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -201,7 +201,7 @@ def dispatch(self, msg): if self.pred_url(url, kwdict): self.update_kwdict(kwdict) self.handle_url(url, kwdict) - else: + if not self.pred_filter_url(url, kwdict): if "filtered" in hooks: for callback in hooks["filtered"]: callback(pathfmt) @@ -218,7 +218,7 @@ def dispatch(self, msg): kwdict[self.metadata_url] = url if self.pred_queue(url, kwdict): self.handle_queue(url, kwdict) - else: + if not self.pred_filter_queue(url, kwdict): if "filtered" in hooks: for callback in hooks["filtered"]: callback(pathfmt) @@ -254,6 +254,23 @@ def _init(self): self.extractor.initialize() self.pred_url = self._prepare_predicates("image", True) self.pred_queue = self._prepare_predicates("chapter", False) + self.pred_filter_url = self._prepare_filter_predicates("image", True) + self.pred_filter_queue = self._prepare_filter_predicates( + "chapter", False) + + def _prepare_filter_predicates(self, target, skip=True): + predicates = [] + + pfilter = self.extractor.config(target + "-filter") + if pfilter: + try: + pred = util.FilterPredicate(pfilter, target) + except (SyntaxError, ValueError, TypeError) as exc: + self.extractor.log.warning(exc) + else: + predicates.append(pred) + + return util.build_predicate(predicates) def _prepare_predicates(self, target, skip=True): predicates = []