Skip to content

Bulk asynchronous downloader for multiple file hosts

fix: profile downloads (chevereto) (#1019)

NTFSvolume634805c8bb4b
diff --git a/cyberdrop_dl/crawlers/_chevereto.py b/cyberdrop_dl/crawlers/_chevereto.py
index b89f9ef69..927f2341a 100644
--- a/cyberdrop_dl/crawlers/_chevereto.py
+++ b/cyberdrop_dl/crawlers/_chevereto.py
@@ -37,7 +37,10 @@ class Media(StrEnum):
def clean_name(url: URL) -> URL:
- return url.with_name(url.name.replace(".md.", ".").replace(".th.", "."))
+ new_name = url.name
+ for trash in (".md.", ".th.", ".fr."):
+ new_name = new_name.replace(trash, ".")
+ return url.with_name(new_name)
def sort_by_new(url: URL) -> URL:
@@ -56,7 +59,7 @@ class CheveretoCrawler(Crawler):
return await self._fetch_chevereto_defaults(scrape_item)
async def _fetch_chevereto_defaults(self, scrape_item: ScrapeItem) -> None:
- if scrape_item.url.host.count(".") > 1: # type: ignore
+ if scrape_item.url.host.removeprefix("www.").count(".") > 1:
return await self.handle_direct_link(scrape_item)
if any(part in scrape_item.url.parts for part in ALBUM_PARTS):
return await self.album(scrape_item)
@@ -78,12 +81,13 @@ class CheveretoCrawler(Crawler):
title = self.create_title(title)
scrape_item.setup_as_profile(title)
- for _, new_scrape_item in self.iter_children(scrape_item, soup, ITEM_SELECTOR):
+ for thumb, new_scrape_item in self.iter_children(scrape_item, soup, ITEM_SELECTOR):
# Item may be an image, a video or an album
# For images, we can download the file from the thumbnail
+ assert thumb
if any(part in new_scrape_item.url.parts for part in IMAGES_PARTS):
_, new_scrape_item.url = self.get_canonical_url(new_scrape_item.url, Media.IMAGE)
- await self.image(new_scrape_item)
+ await self.handle_direct_link(new_scrape_item, thumb)
continue
# For videos and albums, we have to keep scraping
self.manager.task_group.create_task(self.run(new_scrape_item))
@@ -105,10 +109,15 @@ class CheveretoCrawler(Crawler):
for thumb, new_scrape_item in self.iter_children(scrape_item, soup, ITEM_SELECTOR):
assert thumb
- if self.check_album_results(thumb, results):
+ source = clean_name(thumb)
+ if self.check_album_results(source, results):
continue
- _, new_scrape_item.url = self.get_canonical_url(new_scrape_item.url, Media.IMAGE)
- await self.handle_direct_link(new_scrape_item, thumb)
+ if any(part in new_scrape_item.url.parts for part in IMAGES_PARTS):
+ _, new_scrape_item.url = self.get_canonical_url(new_scrape_item.url, Media.IMAGE)
+ await self.handle_direct_link(new_scrape_item, thumb)
+ continue
+
+ self.manager.task_group.create_task(self.run(new_scrape_item))
# Sub album URL needs to be the full URL + a 'sub'
# Using the canonical URL + 'sub' won't work because it redirects to the "homepage" of the album
diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.py
index c67daff9e..cdf2629ee 100644
--- a/cyberdrop_dl/crawlers/crawler.py
+++ b/cyberdrop_dl/crawlers/crawler.py
@@ -39,7 +39,6 @@ if TYPE_CHECKING:
from aiohttp_client_cache.response import AnyResponse
from bs4 import BeautifulSoup, Tag
- from bs4.css import CSS
from cyberdrop_dl.clients.scraper_client import ScraperClient
from cyberdrop_dl.managers.manager import Manager
@@ -332,16 +331,18 @@ class Crawler(ABC):
: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 {}
- css: CSS = soup.css # type: ignore
- for tag in css.iselect(selector):
- link_str: str = tag.get(attribute) # type: ignore
+ for tag in soup.css.iselect(selector):
+ link_str: str | None = tag.get(attribute) # type: ignore
if not link_str:
continue
link = self.parse_url(link_str)
if self.check_album_results(link, album_results):
continue
- thumb_str: str | None = t_tag["src"] if (t_tag := tag.select_one("img")) and "src" in t_tag else None # type: ignore
+ if t_tag := tag.select_one("img"):
+ thumb_str: str | None = t_tag.get("src")
+ else:
+ thumb_str = None
thumb = self.parse_url(thumb_str) if thumb_str else None
yield thumb, link