Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
fix: duplicate pixhosts entries in database
NTFSvolumed25569fabcf0
diff --git a/cyberdrop_dl/scraper/crawlers/pixhost_crawler.py b/cyberdrop_dl/scraper/crawlers/pixhost_crawler.pyindex ea83eae89..14d294c8a 100644--- a/cyberdrop_dl/scraper/crawlers/pixhost_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/pixhost_crawler.py@@ -14,8 +14,11 @@ if TYPE_CHECKING:from cyberdrop_dl.managers.manager import Manager+PRIMARY_BASE_DOMAIN = URL("https://pixhost.to/")++class PixHostCrawler(Crawler):- primary_base_domain = URL("https://pixhost.to/")+ primary_base_domain = PRIMARY_BASE_DOMAINupdate_unsupported = Truedef __init__(self, manager: Manager) -> None:@@ -27,7 +30,9 @@ class PixHostCrawler(Crawler):async def fetch(self, scrape_item: ScrapeItem) -> None:"""Determines where to send the scrape item based on the url."""if is_thumbnail(scrape_item.url):- await self.handle_direct_link(scrape_item)+ link = scrape_item.url+ scrape_item.url = get_canonical_url(link)+ await self.handle_direct_link(scrape_item, link)elif "gallery" in scrape_item.url.parts:await self.gallery(scrape_item)elif "show" in scrape_item.url.parts:@@ -57,15 +62,18 @@ class PixHostCrawler(Crawler):if not (thumb_link_str and link_str):continuelink = self.parse_url(link_str)+ link = get_canonical_url(link)thumb_link = self.parse_url(thumb_link_str)- if not self.check_album_results(link, results):+ src = thumbnail_to_img(thumb_link)+ if not self.check_album_results(src, results):new_scrape_item = self.create_scrape_item(scrape_item, link, add_parent=scrape_item.url)- await self.handle_direct_link(new_scrape_item, thumb_link)+ await self.handle_direct_link(new_scrape_item, src)scrape_item.add_children()@error_handling_wrapperasync def image(self, scrape_item: ScrapeItem) -> None:"""Scrapes an image."""+if await self.check_complete_from_referer(scrape_item):return@@ -80,19 +88,27 @@ class PixHostCrawler(Crawler):async def handle_direct_link(self, scrape_item: ScrapeItem, url: URL | None = None):link = url or scrape_item.urlif is_thumbnail(link):- link = self.thumbnail_to_img(link)+ link = thumbnail_to_img(link)filename, ext = get_filename_and_ext(link.name)await self.handle_file(link, scrape_item, filename, ext)- def thumbnail_to_img(self, url: URL):- assert url.host- thumb_server_id: str = url.host.split(".", 1)[0].split("t")[-1]- img_host = f"img{thumb_server_id}.{self.primary_base_domain.host}"- new_parts = ["images"] + [p for p in url.parts if p not in ("thumbs", "/")]- new_path = "/".join(new_parts)- return url.with_host(img_host).with_path(new_path)++def thumbnail_to_img(url: URL) -> URL:+ assert url.host+ thumb_server_id: str = url.host.split(".", 1)[0].split("t")[-1]+ img_host = f"img{thumb_server_id}.{PRIMARY_BASE_DOMAIN.host}"+ new_parts = ["images"] + [p for p in url.parts if p not in ("thumbs", "/")]+ new_path = "/".join(new_parts)+ return url.with_host(img_host).with_path(new_path)def is_thumbnail(url: URL) -> bool:assert url.hostreturn "thumbs" in url.parts and len(url.host.split(".")) >= 2+++def get_canonical_url(url: URL) -> URL:+ new_parts = list(url.parts)[1:]+ new_parts[0] = "show"+ new_path = "/".join(new_parts)+ return PRIMARY_BASE_DOMAIN / new_path