Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
replace code with status to fall in line with aiohttp deprecation
Jules-WinnfieldX968faf05ec4f
diff --git a/cyberdrop_dl/base_functions/error_classes.py b/cyberdrop_dl/base_functions/error_classes.pyindex 32fef6a17..6cadb8386 100644--- a/cyberdrop_dl/base_functions/error_classes.py+++ b/cyberdrop_dl/base_functions/error_classes.py@@ -27,8 +27,8 @@ class InvalidContentTypeFailure(Exception):class DownloadFailure(Exception):"""This error will be thrown when a download fails"""- def __init__(self, code: int, message: str = "Something went wrong"):- self.code = code+ def __init__(self, status: int, message: str = "Something went wrong"):+ self.status = statusself.message = messagesuper().__init__(self.message)- super().__init__(self.code)+ super().__init__(self.status)diff --git a/cyberdrop_dl/client/client.py b/cyberdrop_dl/client/client.pyindex b7b3a2346..9c6bec3c3 100644--- a/cyberdrop_dl/client/client.py+++ b/cyberdrop_dl/client/client.py@@ -166,14 +166,14 @@ class DownloadSession:raise_for_status=True, proxy=proxy) as resp:content_type = resp.headers.get('Content-Type')if not content_type:- raise DownloadFailure(code=CustomHTTPStatus.IM_A_TEAPOT, message="No content-type in response header")+ raise DownloadFailure(status=CustomHTTPStatus.IM_A_TEAPOT, message="No content-type in response header")if resp.url in self.bunkr_maintenance:- raise DownloadFailure(code=HTTPStatus.SERVICE_UNAVAILABLE, message="Bunkr under maintenance")+ raise DownloadFailure(status=HTTPStatus.SERVICE_UNAVAILABLE, message="Bunkr under maintenance")extname = Path(media.filename).suffix.lower()if any(s in content_type.lower() for s in ('html', 'text')) and extname not in FILE_FORMATS['Text']:logger.debug("Server for %s is experiencing issues, you are being ratelimited, or cookies have expired", media.url)- raise DownloadFailure(code=CustomHTTPStatus.IM_A_TEAPOT, message="Unexpectedly got text as response")+ raise DownloadFailure(status=CustomHTTPStatus.IM_A_TEAPOT, message="Unexpectedly got text as response")if resp.status != HTTPStatus.PARTIAL_CONTENT:if file.is_file():diff --git a/cyberdrop_dl/downloader/downloader_utils.py b/cyberdrop_dl/downloader/downloader_utils.pyindex 6d36c444a..9a993f350 100644--- a/cyberdrop_dl/downloader/downloader_utils.py+++ b/cyberdrop_dl/downloader/downloader_utils.py@@ -80,7 +80,7 @@ def retry(f):return Nonelogger.debug(e.message)logger.debug(f'Retrying ({self.current_attempt[url_path]}) {media.url}...')- if e.code != 999:+ if e.status != 999:self.current_attempt[url_path] += 1return wrapperdiff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.pyindex e3b5a715d..e3e5a39bd 100644--- a/cyberdrop_dl/downloader/downloaders.py+++ b/cyberdrop_dl/downloader/downloaders.py@@ -269,10 +269,10 @@ class Downloader:elif self.current_attempt_filesize[filename] > size:self.current_attempt_filesize[filename] = sizeelse:- raise DownloadFailure(code=getattr(e, "code", 1), message="Download timeout reached, retrying")- raise DownloadFailure(code=999, message="Download timeout reached, retrying")+ raise DownloadFailure(status=getattr(e, "status", 1), message="Download timeout reached, retrying")+ raise DownloadFailure(status=999, message="Download timeout reached, retrying")- raise DownloadFailure(code=getattr(e, "code", 1), message=repr(e))+ raise DownloadFailure(status=getattr(e, "status", 1), message=repr(e))except (aiohttp.client_exceptions.ClientPayloadError, aiohttp.client_exceptions.ClientOSError,aiohttp.client_exceptions.ClientResponseError, DownloadFailure, FileNotFoundError,@@ -286,17 +286,17 @@ class Downloader:if hasattr(e, "message"):logging.debug(f"\n{media.url} ({e.message})")- if hasattr(e, "code"):- if await is_4xx_client_error(e.code) and e.code != HTTPStatus.TOO_MANY_REQUESTS:- logger.debug("We ran into a 400 level error: %s", e.code)+ if hasattr(e, "status"):+ if await is_4xx_client_error(e.status) and e.status != HTTPStatus.TOO_MANY_REQUESTS:+ logger.debug("We ran into a 400 level error: %s", e.status)log(f"Failed Download: {media.filename}", quiet=True)if url_path in self.current_attempt:self.current_attempt.pop(url_path)await self.handle_failed(media, e)return- if e.code == HTTPStatus.SERVICE_UNAVAILABLE or e.code == HTTPStatus.BAD_GATEWAY \- or e.code == CustomHTTPStatus.WEB_SERVER_IS_DOWN:+ if e.status == HTTPStatus.SERVICE_UNAVAILABLE or e.status == HTTPStatus.BAD_GATEWAY \+ or e.status == CustomHTTPStatus.WEB_SERVER_IS_DOWN:if hasattr(e, "message"):if not e.message:e.message = "Web server is down"@@ -307,9 +307,9 @@ class Downloader:await self.handle_failed(media, e)return- logger.debug("Error status code: %s", e.code)+ logger.debug("Error status code: %s", e.status)- raise DownloadFailure(code=getattr(e, "code", 1), message=repr(e))+ raise DownloadFailure(status=getattr(e, "status", 1), message=repr(e))def can_retry(self, url_path: str) -> bool:return self.CDL_Helper.disable_attempt_limit or self.current_attempt[diff --git a/cyberdrop_dl/downloader/old_downloaders.py b/cyberdrop_dl/downloader/old_downloaders.pyindex f5aedaf92..6408a25ad 100644--- a/cyberdrop_dl/downloader/old_downloaders.py+++ b/cyberdrop_dl/downloader/old_downloaders.py@@ -223,15 +223,15 @@ class Old_Downloader:if hasattr(e, "message"):logging.debug(f"\n{media.url} ({e.message})")- if hasattr(e, "code"):- if await is_4xx_client_error(e.code) and e.code != HTTPStatus.TOO_MANY_REQUESTS:- logger.debug("We ran into a 400 level error: %s", e.code)+ if hasattr(e, "status"):+ if await is_4xx_client_error(e.status) and e.status != HTTPStatus.TOO_MANY_REQUESTS:+ logger.debug("We ran into a 400 level error: %s", e.status)log(f"Failed Download: {media.filename}", quiet=True)if url_path in self.current_attempt:self.current_attempt.pop(url_path)await self.handle_failed(media, e)return- if e.code == HTTPStatus.SERVICE_UNAVAILABLE or e.code == CustomHTTPStatus.WEB_SERVER_IS_DOWN:+ if e.status == HTTPStatus.SERVICE_UNAVAILABLE or e.status == CustomHTTPStatus.WEB_SERVER_IS_DOWN:if hasattr(e, "message"):if not e.message:e.message = "Web server is down"@@ -241,9 +241,9 @@ class Old_Downloader:self.current_attempt.pop(url_path)await self.handle_failed(media, e)return- logger.debug("Error status code: %s", e.code)+ logger.debug("Error status code: %s", e.status)- raise DownloadFailure(code=getattr(e, "code", 1), message=repr(e))+ raise DownloadFailure(status=getattr(e, "status", 1), message=repr(e))def can_retry(self, url_path: str) -> bool:return self.disable_attempt_limit or self.current_attempt[url_path] < self.allowed_attempts - 1