Skip to content

Bulk asynchronous downloader for multiple file hosts

Update scraper_client.py

Jacob2fda7fe886cb
diff --git a/cyberdrop_dl/clients/scraper_client.py b/cyberdrop_dl/clients/scraper_client.py
index d6d34dab8..6fc0bb78b 100644
--- a/cyberdrop_dl/clients/scraper_client.py
+++ b/cyberdrop_dl/clients/scraper_client.py
@@ -30,8 +30,8 @@ def limiter(func):
await domain_limiter.acquire()
async with aiohttp.ClientSession(headers=self._headers, raise_for_status=False,
- cookie_jar=self.client_manager.cookies, timeout=self._timeouts,
- trace_configs=self.trace_configs) as client:
+ cookie_jar=self.client_manager.cookies, timeout=self._timeouts,
+ trace_configs=self.trace_configs) as client:
kwargs['client_session'] = client
return await func(self, *args, **kwargs)
@@ -45,7 +45,7 @@ class ScraperClient:
self.client_manager = client_manager
self._headers = {"user-agent": client_manager.user_agent}
self._timeouts = aiohttp.ClientTimeout(total=client_manager.connection_timeout + 60,
- connect=client_manager.connection_timeout)
+ connect=client_manager.connection_timeout)
self._global_limiter = self.client_manager.global_rate_limiter
self.trace_configs = []
@@ -65,7 +65,7 @@ class ScraperClient:
@limiter
async def flaresolverr(self, domain: str, url: URL, client_session: ClientSession,
- origin: Optional[ScrapeItem | URL] = None, with_response_url: bool = False) -> str:
+ origin: Optional[ScrapeItem | URL] = None, with_response_url: bool = False) -> str:
"""Returns the resolved URL from the given URL"""
if not self.client_manager.flaresolverr:
raise DDOSGuardFailure(message="FlareSolverr is not configured", origin=origin)
@@ -74,8 +74,8 @@ class ScraperClient:
data = {"cmd": "request.get", "url": str(url), "maxTimeout": 60000}
async with client_session.post(f"http://{self.client_manager.flaresolverr}/v1", headers=headers,
- ssl=self.client_manager.ssl_context,
- proxy=self.client_manager.proxy, json=data) as response:
+ ssl=self.client_manager.ssl_context,
+ proxy=self.client_manager.proxy, json=data) as response:
json_obj: dict = await response.json()
status = json_obj.get("status")
if status != "ok":
@@ -90,10 +90,10 @@ class ScraperClient:
@limiter
async def get_BS4(self, domain: str, url: URL, client_session: ClientSession,
- origin: Optional[ScrapeItem | URL] = None, with_response_url: bool = False) -> BeautifulSoup:
+ origin: Optional[ScrapeItem | URL] = None, with_response_url: bool = False) -> BeautifulSoup:
"""Returns a BeautifulSoup object from the given URL"""
async with client_session.get(url, headers=self._headers, ssl=self.client_manager.ssl_context,
- proxy=self.client_manager.proxy) as response:
+ proxy=self.client_manager.proxy) as response:
try:
await self.client_manager.check_http_status(response, origin=origin)
except DDOSGuardFailure:
@@ -112,19 +112,19 @@ class ScraperClient:
return BeautifulSoup(text, 'html.parser')
async def get_BS4_and_return_URL(self, domain: str, url: URL,
- origin: Optional[ScrapeItem | URL] = None) -> tuple[
+ origin: Optional[ScrapeItem | URL] = None) -> tuple[
BeautifulSoup, URL]:
"""Returns a BeautifulSoup object and response URL from the given URL"""
return await self.get_BS4(domain, url, origin = origin, with_response_url = True)
@limiter
async def get_json(self, domain: str, url: URL, params: Optional[Dict] = None, headers_inc: Optional[Dict] = None,
- client_session: ClientSession = None, origin: Optional[ScrapeItem | URL] = None) -> Dict:
+ client_session: ClientSession = None, origin: Optional[ScrapeItem | URL] = None) -> Dict:
"""Returns a JSON object from the given URL"""
headers = {**self._headers, **headers_inc} if headers_inc else self._headers
async with client_session.get(url, headers=headers, ssl=self.client_manager.ssl_context,
- proxy=self.client_manager.proxy, params=params) as response:
+ proxy=self.client_manager.proxy, params=params) as response:
await self.client_manager.check_http_status(response, origin=origin)
content_type = response.headers.get('Content-Type')
assert content_type is not None
@@ -134,10 +134,10 @@ class ScraperClient:
@limiter
async def get_text(self, domain: str, url: URL, client_session: ClientSession,
- origin: Optional[ScrapeItem | URL] = None) -> str:
+ origin: Optional[ScrapeItem | URL] = None) -> str:
"""Returns a text object from the given URL"""
async with client_session.get(url, headers=self._headers, ssl=self.client_manager.ssl_context,
- proxy=self.client_manager.proxy) as response:
+ proxy=self.client_manager.proxy) as response:
try:
await self.client_manager.check_http_status(response, origin=origin)
except DDOSGuardFailure:
@@ -152,7 +152,7 @@ class ScraperClient:
origin: Optional[ScrapeItem | URL] = None) -> Dict:
"""Returns a JSON object from the given URL when posting data. If raw == True, returns raw binary data of response"""
async with client_session.post(url, headers=self._headers, ssl=self.client_manager.ssl_context,
- proxy=self.client_manager.proxy, data=data) as response:
+ proxy=self.client_manager.proxy, data=data) as response:
await self.client_manager.check_http_status(response, origin=origin)
if req_resp:
content = await response.content.read()
@@ -166,5 +166,5 @@ class ScraperClient:
async def get_head(self, domain: str, url: URL, client_session: ClientSession) -> CIMultiDictProxy[str]:
"""Returns the headers from the given URL"""
async with client_session.head(url, headers=self._headers, ssl=self.client_manager.ssl_context,
- proxy=self.client_manager.proxy) as response:
+ proxy=self.client_manager.proxy) as response:
return response.headers