Skip to content

Bulk asynchronous downloader for multiple file hosts

revert cloudflare changes (#350)

datawhores20d28cb2232a
diff --git a/cyberdrop_dl/managers/client_manager.py b/cyberdrop_dl/managers/client_manager.py
index 7eec2c27c..90c49878c 100644
--- a/cyberdrop_dl/managers/client_manager.py
+++ b/cyberdrop_dl/managers/client_manager.py
@@ -120,27 +120,14 @@ class ClientManager:
"""Checks the HTTP status code and raises an exception if it's not acceptable."""
status = response.status
headers = response.headers
- # for downloads
- if not download:
- pass
- elif headers.get("ETag") in DOWNLOAD_ERROR_ETAGS:
+
+ if download and headers.get("ETag") in DOWNLOAD_ERROR_ETAGS:
message = DOWNLOAD_ERROR_ETAGS.get(headers.get("ETag"))
raise DownloadError(HTTPStatus.NOT_FOUND, message=message, origin=origin)
- elif HTTPStatus.OK <= status < HTTPStatus.BAD_REQUEST:
- return
-
- # for text,etc
- response_text = None
- with contextlib.suppress(UnicodeDecodeError):
- response_text = await response.text()
-
- if response_text:
- soup = BeautifulSoup(response_text, "html.parser")
- if cls.check_ddos_guard(soup) or cls.check_cloudflare(soup):
- raise DDOSGuardError(origin=origin)
if HTTPStatus.OK <= status < HTTPStatus.BAD_REQUEST:
return
+
if any(domain in response.url.host for domain in ("gofile", "imgur")):
with contextlib.suppress(ContentTypeError):
JSON_Resp: dict = await response.json()
@@ -149,6 +136,14 @@ class ClientManager:
if "data" in JSON_Resp and "error" in JSON_Resp["data"]:
raise ScrapeError(JSON_Resp["status"], JSON_Resp["data"]["error"], origin=origin)
+ response_text = None
+ with contextlib.suppress(UnicodeDecodeError):
+ response_text = await response.text()
+
+ if response_text:
+ soup = BeautifulSoup(response_text, "html.parser")
+ if cls.check_ddos_guard(soup) and cls.check_cloudflare(soup):
+ raise DDOSGuardError(origin=origin)
status = status if headers.get("Content-Type") else CustomHTTPStatus.IM_A_TEAPOT
message = "No content-type in response header" if headers.get("Content-Type") else None