Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
add status and proper scrapefailure error
Jules-WinnfieldX260e0054ddef
diff --git a/cyberdrop_dl/clients/errors.py b/cyberdrop_dl/clients/errors.pyindex 8de28d4ff..7d2d6e016 100644--- a/cyberdrop_dl/clients/errors.py+++ b/cyberdrop_dl/clients/errors.py@@ -21,8 +21,19 @@ class DownloadFailure(Exception):super().__init__(self.status)+class ScrapeFailure(Exception):+ """This error will be thrown when a request fails"""+ def __init__(self, status: int, message: str = "Something went wrong"):+ self.status = status+ self.message = message+ super().__init__(self.message)+ super().__init__(self.status)++class FailedLoginFailure(Exception):"""This error will be thrown when the login fails for a site"""- def __init__(self, *, message: str = "Failed login."):+ def __init__(self, *, status: int, message: str = "Failed login."):+ self.status = statusself.message = messagesuper().__init__(self.message)+ super().__init__(self.status)diff --git a/cyberdrop_dl/scraper/crawler.py b/cyberdrop_dl/scraper/crawler.pyindex b8486770c..1ffa3c6b3 100644--- a/cyberdrop_dl/scraper/crawler.py+++ b/cyberdrop_dl/scraper/crawler.py@@ -100,14 +100,14 @@ class Crawler(ABC):response_url=URL("https://" + login_url.host))if (not username or not password) and not session_cookie:await log(f"Login wasn't provided for {login_url.host}")- raise FailedLoginFailure(message="Login wasn't provided")+ raise FailedLoginFailure(status=401, message="Login wasn't provided")attempt = 0while True:while True:try:if attempt == 5:- raise FailedLoginFailure(message="Failed to login after 5 attempts")+ raise FailedLoginFailure(status=403, message="Failed to login after 5 attempts")assert login_url.host is not Nonediff --git a/cyberdrop_dl/scraper/crawlers/gofile_crawler.py b/cyberdrop_dl/scraper/crawlers/gofile_crawler.pyindex 884c51e68..3f9a7ea45 100644--- a/cyberdrop_dl/scraper/crawlers/gofile_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/gofile_crawler.py@@ -9,6 +9,7 @@ import aiohttp.client_exceptionsfrom aiolimiter import AsyncLimiterfrom yarl import URL+from cyberdrop_dl.clients.errors import ScrapeFailurefrom cyberdrop_dl.scraper.crawler import Crawlerfrom cyberdrop_dl.utils.dataclasses.url_objects import ScrapeItemfrom cyberdrop_dl.utils.utilities import get_filename_and_ext, error_handling_wrapper@@ -62,7 +63,7 @@ class GoFileCrawler(Crawler):JSON_Resp = await self.client.get_json(self.domain, self.api_address / "getContent", params)if JSON_Resp["status"] != "ok":- raise Exception("Does Not Exist")+ raise ScrapeFailure(404, "Does Not Exist")JSON_Resp = JSON_Resp['data']title = JSON_Resp["name"] + f" ({scrape_item.url.host})"@@ -107,7 +108,7 @@ class GoFileCrawler(Crawler):self.token = JSON_Resp["data"]["token"]await self.set_cookie(session)else:- raise Exception("Couldn't generate GoFile token")+ raise ScrapeFailure(403, "Couldn't generate GoFile token")@error_handling_wrapperasync def get_website_token(self, session: ScraperClient) -> None:@@ -125,7 +126,7 @@ class GoFileCrawler(Crawler):text = str(text)self.websiteToken = re.search(r'fetchData\.websiteToken\s*=\s*"(.*?)"', text).group(1)if not self.websiteToken:- raise Exception("Couldn't generate GoFile websiteToken")+ raise ScrapeFailure(403, "Couldn't generate GoFile websiteToken")self.manager.cache_manager.save("gofile_website_token", self.websiteToken)async def set_cookie(self, session: ScraperClient) -> None:diff --git a/cyberdrop_dl/scraper/crawlers/imgur_crawler.py b/cyberdrop_dl/scraper/crawlers/imgur_crawler.pyindex 78dc6d008..b3f9cc851 100644--- a/cyberdrop_dl/scraper/crawlers/imgur_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/imgur_crawler.py@@ -5,6 +5,7 @@ from typing import TYPE_CHECKINGfrom aiolimiter import AsyncLimiterfrom yarl import URL+from cyberdrop_dl.clients.errors import ScrapeFailurefrom cyberdrop_dl.scraper.crawler import Crawlerfrom cyberdrop_dl.utils.dataclasses.url_objects import ScrapeItemfrom cyberdrop_dl.utils.utilities import error_handling_wrapper, log, get_filename_and_ext@@ -42,7 +43,7 @@ class ImgurCrawler(Crawler):"""Scrapes an album"""if self.imgur_client_id == "":await log("To scrape imgur content, you need to provide a client id")- raise Exception("No Imgur Client ID provided")+ raise ScrapeFailure(401, "No Imgur Client ID provided")await self.check_imgur_credits()album_id = scrape_item.url.parts[-1]@@ -68,7 +69,7 @@ class ImgurCrawler(Crawler):"""Scrapes an image"""if self.imgur_client_id == "":await log("To scrape imgur content, you need to provide a client id")- raise Exception("No Imgur Client ID provided")+ raise ScrapeFailure(401, "No Imgur Client ID provided")await self.check_imgur_credits()image_id = scrape_item.url.parts[-1]@@ -97,4 +98,4 @@ class ImgurCrawler(Crawler):credits_obj = await self.client.get_json(self.domain, self.imgur_api / "credits", headers_inc=self.headers)self.imgur_client_remaining = credits_obj["data"]["ClientRemaining"]if self.imgur_client_remaining < 100:- raise Exception("Imgur API rate limit reached")+ raise ScrapeFailure(429, "Imgur API rate limit reached")