Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: delete old thumbnails method
NTFSvolume1810f158013a
diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.pyindex 836cf2e83..9b3569ac7 100644--- a/cyberdrop_dl/crawlers/crawler.py+++ b/cyberdrop_dl/crawlers/crawler.py@@ -731,47 +731,14 @@ class Crawler(HTTPMixin, HLSMixin, ABC):response_url = url or self.PRIMARY_URLself.client.cookies.update_cookies(cookies, response_url)- @final- def iter_thumbnails(- self,- soup: Tag,- selector: str,- /,- attribute: str = "href",- *,- results: Mapping[str, bool] | None = None,- ) -> Generator[tuple[AbsoluteHttpURL | None, AbsoluteHttpURL]]:- """Generates tuples with an URL from the `src` value of the first image tag (AKA the thumbnail) and an URL from the value of `attribute`-- :param results: must be the output of `self.get_album_results`.- If provided, it will be used as a filter, to only yield items that has not been downloaded before"""- album_results = results or {}-- seen: set[str] = set()- for tag in css.iselect(soup, selector):- link_str: str | None = css.attr_or_none(tag, attribute)- if not link_str or link_str in seen:- continue- seen.add(link_str)- link = self.parse_url(link_str)- if self.check_album_results(link, album_results):- continue- try:- thumb_str: str | None = css.select(tag, "img", "src")- except css.SelectorError:- thumb = None- else:- thumb = None if is_blob_or_svg(thumb_str) else self.parse_url(thumb_str)-- yield thumb, link-@final@classmethoddef iter_urls(cls, tag: Tag, selector: str, attribute: str = "href", origin: AbsoluteHttpURL | None = None) -> Generator[AbsoluteHttpURL]:for url in unique(css.iselect(tag, selector, attribute)):- yield cls.parse_url(url, origin)+ if not is_blob_or_svg(url):+ yield cls.parse_url(url, origin)@finalasync def make_album_checker(self, album_id: str) -> Callable[[AbsoluteHttpURL], bool]:diff --git a/cyberdrop_dl/crawlers/pixhost.py b/cyberdrop_dl/crawlers/pixhost.pyindex 3c70a64da..b225dab06 100644--- a/cyberdrop_dl/crawlers/pixhost.py+++ b/cyberdrop_dl/crawlers/pixhost.py@@ -12,7 +12,7 @@ if TYPE_CHECKING:class Selector:GALLERY_TITLE = "a.link h2"- GALLERY_IMAGES = "div.images a"+ GALLERY_IMAGES = "div.images a img"IMAGE = "img.image-img"@@ -49,15 +49,10 @@ class PixHostCrawler(Crawler):title = css.select_text(soup, Selector.GALLERY_TITLE)title = self.create_title(title, album_id)scrape_item.setup_as_album(title, album_id=album_id)- results = await self.get_album_results(album_id)-- for thumb, web_url in self.iter_thumbnails(soup, Selector.GALLERY_IMAGES):- assert thumb- src = _thumbnail_to_src(thumb)- if self.check_album_results(src, results):- continue- new_scrape_item = scrape_item.create_child(web_url)- self.create_task(self.direct_file(new_scrape_item, src))+ should_download = await self.make_album_checker(album_id)+ urls = map(_thumbnail_to_src, self.iter_urls(soup, Selector.GALLERY_IMAGES, "src"))+ for src in filter(should_download, urls):+ self.create_task(self.direct_file(scrape_item, src))scrape_item.add_children()@error_handling_wrapper