Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: add videos support (chevereto) (#448)
NTFSvolume798dd11b113f
diff --git a/cyberdrop_dl/scraper/crawlers/chevereto_crawler.py b/cyberdrop_dl/scraper/crawlers/chevereto_crawler.pyindex e30952a54..a5e719bfc 100644--- a/cyberdrop_dl/scraper/crawlers/chevereto_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/chevereto_crawler.py@@ -11,7 +11,7 @@ from bs4 import BeautifulSoupfrom yarl import URLfrom cyberdrop_dl.clients.errors import PasswordProtectedError, ScrapeError-from cyberdrop_dl.scraper.crawler import Crawler+from cyberdrop_dl.scraper.crawler import Crawler, create_task_idfrom cyberdrop_dl.utils.utilities import error_handling_wrapper, get_filename_and_extif TYPE_CHECKING:@@ -32,6 +32,7 @@ CDN_POSSIBILITIES = re.compile("|".join(CDN_PATTERNS.values()))class UrlType(enum.StrEnum):album = enum.auto()image = enum.auto()+ video = enum.auto()class CheveretoCrawler(Crawler):@@ -79,27 +80,25 @@ class CheveretoCrawler(Crawler):self.profile_title_selector = 'meta[property="og:title"]'self.images_parts = "image", "img", "images"self.album_parts = "a", "album"+ self.video_parts = "video", "videos""""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""+ @create_task_idasync def fetch(self, scrape_item: ScrapeItem) -> None:"""Determines where to send the scrape item based on the url."""- task_id = self.scraping_progress.add_task(scrape_item.url)-if self.check_direct_link(scrape_item.url):await self.handle_direct_link(scrape_item)+ return+ scrape_item.url = scrape_item.url.with_host(self.primary_base_domain.host)+ if any(part in scrape_item.url.parts for part in self.album_parts):+ await self.album(scrape_item)+ elif any(part in scrape_item.url.parts for part in self.images_parts):+ await self.image(scrape_item)+ elif any(part in scrape_item.url.parts for part in self.video_parts):+ await self.video(scrape_item)else:- scrape_item.url = self.primary_base_domain.with_path(scrape_item.url.path[1:]).with_query(- scrape_item.url.query,- )- if any(part in scrape_item.url.parts for part in self.album_parts):- await self.album(scrape_item)- elif any(part in scrape_item.url.parts for part in self.images_parts):- await self.image(scrape_item)- else:- await self.profile(scrape_item)-- self.scraping_progress.remove_task(task_id)+ await self.profile(scrape_item)@error_handling_wrapperasync def profile(self, scrape_item: ScrapeItem) -> None:@@ -130,7 +129,7 @@ class CheveretoCrawler(Crawler):@error_handling_wrapperasync def album(self, scrape_item: ScrapeItem) -> None:"""Scrapes an album."""- album_id, scrape_item.url = self.get_canonical_url(scrape_item)+ album_id, canonical_url = self.get_canonical_url(scrape_item)results = await self.get_album_results(album_id)scrape_item.album_id = album_idscrape_item.part_of_album = True@@ -139,11 +138,11 @@ class CheveretoCrawler(Crawler):async with self.request_limiter:sub_albums_soup: BeautifulSoup = await self.client.get_soup(- self.domain,- scrape_item.url / "sub",- origin=scrape_item,+ self.domain, scrape_item.url / "sub", origin=scrape_item)+ scrape_item.url = canonical_url+if "This content is password protected" in sub_albums_soup.text and password:password_data = {"content-password": password}async with self.request_limiter:@@ -195,24 +194,38 @@ class CheveretoCrawler(Crawler):if not self.check_album_results(link, results):await self.handle_direct_link(new_scrape_item)- @error_handling_wrapper+ async def video(self, scrape_item: ScrapeItem) -> None:+ """Scrapes a video."""+ url_type = UrlType.video+ selector = "meta[property='og:video']", "content"+ await self._proccess_media_item(scrape_item, url_type, selector)+async def image(self, scrape_item: ScrapeItem) -> None:"""Scrapes an image."""+ url_type = UrlType.image+ selector = "div[id=image-viewer] img", "src"+ await self._proccess_media_item(scrape_item, url_type, selector)++ @error_handling_wrapper+ async def _proccess_media_item(self, scrape_item: ScrapeItem, url_type: UrlType, selector: tuple[str, str]) -> None:+ """Scrapes a media item."""if await self.check_complete_from_referer(scrape_item):return- _, scrape_item.url = self.get_canonical_url(scrape_item, url_type=UrlType.image)- if await self.check_complete_from_referer(scrape_item):+ _, canonical_url = self.get_canonical_url(scrape_item, url_type=url_type)+ if await self.check_complete_from_referer(canonical_url):returnasync with self.request_limiter:soup: BeautifulSoup = await self.client.get_soup(self.domain, scrape_item.url, origin=scrape_item)+ scrape_item.url = canonical_url+try:- link = URL(soup.select_one("div[id=image-viewer] img").get("src"))+ link = URL(soup.select_one(selector[0]).get(selector[1]))link = link.with_name(link.name.replace(".md.", ".").replace(".th.", "."))except AttributeError:- raise ScrapeError(422, "Couldn't find img source", origin=scrape_item) from None+ raise ScrapeError(422, f"Couldn't find {url_type.value} source", origin=scrape_item) from Nonedesc_rows = soup.select("p[class*=description-meta]")date = None@@ -240,13 +253,15 @@ class CheveretoCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""def get_canonical_url(self, scrape_item: ScrapeItem, url_type: UrlType = UrlType.album) -> tuple[str, URL]:- "Returns the id and canonical URL from a given item (album or image)"+ "Returns the id and canonical URL from a given item (album, image or video)"if url_type not in UrlType:raise ValueError("Invalid URL Type")search_parts = self.album_partsif url_type == UrlType.image:search_parts = self.images_parts+ elif url_type == UrlType.video:+ search_parts = self.video_partsfound_part = next(part for part in search_parts if part in scrape_item.url.parts)name_index = scrape_item.url.parts.index(found_part) + 1