Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: add API to skip scrapped items

NTFSvolume359782d03201
diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.py
index ed94e328f..d2364819a 100644
--- a/cyberdrop_dl/crawlers/crawler.py
+++ b/cyberdrop_dl/crawlers/crawler.py
@@ -449,6 +449,16 @@ class Crawler(HTTPMixin, HLSMixin, ABC):
catch_errors: Final = error_handling_context
+ @final
+ def was_scrapped_before(self, url: AbsoluteHttpURL) -> bool:
+ lookup = url.path_qs if self.__url_config__.ignore_fragment else _path_qs_frag(url)
+ if lookup in self.scraped_items:
+ logger.info("Skipping %s as it has already been scrapped", url)
+ return True
+
+ self.scraped_items.add(lookup)
+ return False
+
@final
async def run(self, scrape_item: ScrapeItem, *, check_referer: bool = False) -> None:
if self.disabled:
@@ -457,13 +467,9 @@ class Crawler(HTTPMixin, HLSMixin, ABC):
with scrape_item.track_changes:
scrape_item.url = url = self.transform_url(scrape_item.url)
- lookup = url.path_qs if self.__url_config__.ignore_fragment else _path_qs_frag(url)
- if lookup in self.scraped_items:
- logger.info("Skipping %s as it has already been scrapped", url)
+ if self.was_scrapped_before(url):
return
- self.scraped_items.add(lookup)
-
if not self.__url_config__.allow_empty_path and url.path == "/":
self.raise_exc(scrape_item, ScrapeError.unsupported())
return
@@ -1216,13 +1222,15 @@ def _sort_supported_paths(supported_paths: SupportedPaths) -> dict[str, tuple[st
def auto_task_id[CrawlerT: Crawler, **P, R](
func: Callable[Concatenate[CrawlerT, ScrapeItem, P], Coroutine[None, None, R]],
-) -> Callable[Concatenate[CrawlerT, ScrapeItem, P], Coroutine[None, None, R]]:
+) -> Callable[Concatenate[CrawlerT, ScrapeItem, P], Coroutine[None, None, None]]:
"""Autocreate a new `task_id` from the scrape_item of the method"""
@functools.wraps(func)
- async def wrapper(self: CrawlerT, scrape_item: ScrapeItem, *args: P.args, **kwargs: P.kwargs) -> R:
+ async def wrapper(self: CrawlerT, scrape_item: ScrapeItem, *args: P.args, **kwargs: P.kwargs) -> None:
+ if self.was_scrapped_before(scrape_item.url):
+ return
with self.new_task_id(scrape_item.url):
- return await func(self, scrape_item, *args, **kwargs)
+ await func(self, scrape_item, *args, **kwargs)
return wrapper