Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: reduce curl usage at runtime

NTFSvolumeebc90d0f3616
diff --git a/cyberdrop_dl/managers/client_manager.py b/cyberdrop_dl/managers/client_manager.py
index 58601e10a..c2eb339f0 100644
--- a/cyberdrop_dl/managers/client_manager.py
+++ b/cyberdrop_dl/managers/client_manager.py
@@ -14,7 +14,6 @@ import certifi
from aiohttp import ClientResponse, ClientSession, ContentTypeError
from aiolimiter import AsyncLimiter
from bs4 import BeautifulSoup
-from curl_cffi.requests.models import Response as CurlResponse
from yarl import URL
from cyberdrop_dl.clients.download_client import DownloadClient
@@ -26,6 +25,8 @@ from cyberdrop_dl.utils.logger import log, log_spacer
from cyberdrop_dl.utils.utilities import get_soup_from_response
if TYPE_CHECKING:
+ from curl_cffi.requests.models import Response as CurlResponse
+
from cyberdrop_dl.managers.manager import Manager
from cyberdrop_dl.utils.data_enums_classes.url_objects import ScrapeItem
@@ -163,7 +164,7 @@ class ClientManager:
origin: ScrapeItem | URL | None = None,
) -> None:
"""Checks the HTTP status code and raises an exception if it's not acceptable."""
- is_curl = isinstance(response, CurlResponse)
+ is_curl = not isinstance(response, ClientResponse)
status = response.status_code if is_curl else response.status
headers = response.headers
message = None
diff --git a/cyberdrop_dl/utils/utilities.py b/cyberdrop_dl/utils/utilities.py
index 8d3c0b778..49cf71b80 100644
--- a/cyberdrop_dl/utils/utilities.py
+++ b/cyberdrop_dl/utils/utilities.py
@@ -15,7 +15,6 @@ import aiofiles
import rich
from aiohttp import ClientConnectorError, ClientResponse, ClientSession, FormData
from bs4 import BeautifulSoup
-from curl_cffi.requests.models import Response as CurlResponse
from yarl import URL
from cyberdrop_dl.clients.errors import (
@@ -32,6 +31,7 @@ from cyberdrop_dl.utils.logger import log, log_debug, log_spacer, log_with_color
if TYPE_CHECKING:
from collections.abc import Callable
+ from curl_cffi.requests.models import Response as CurlResponse
from rich.text import Text
from cyberdrop_dl.crawlers import Crawler
@@ -415,7 +415,7 @@ def remove_trailing_slash(url: URL) -> URL:
async def get_soup_from_response(response: CurlResponse | ClientResponse) -> BeautifulSoup | None:
response_text = None
with contextlib.suppress(UnicodeDecodeError):
- response_text = response.text if isinstance(response, CurlResponse) else await response.text()
+ response_text = await response.text() if isinstance(response, ClientResponse) else response.text
if not response_text:
return