From 9309e15a121feb69310cb8a3533447cde3b453ad Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Wed, 3 Jul 2024 18:08:50 +0200 Subject: [PATCH] fix: aiohttp max number of simultaneous connections --- comet/api/stream.py | 5 ++--- comet/utils/general.py | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/comet/api/stream.py b/comet/api/stream.py index aa884d8..3395599 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -31,7 +31,8 @@ async def stream(request: Request, b64config: str, type: str, id: str): ] } - async with aiohttp.ClientSession() as session: + connector = aiohttp.TCPConnector(limit=0) + async with aiohttp.ClientSession(connector=connector) as session: check_debrid = await session.get("https://api.real-debrid.com/rest/1.0/user", headers={ "Authorization": f"Bearer {config['debridApiKey']}" }) @@ -80,7 +81,6 @@ async def stream(request: Request, b64config: str, type: str, id: str): sorted_ranked_files = json.loads(sorted_ranked_files[0]) balanced_hashes = await get_balanced_hashes(sorted_ranked_files, config) - results = [] for hash in sorted_ranked_files: for resolution in balanced_hashes: @@ -253,7 +253,6 @@ async def stream(request: Request, b64config: str, type: str, id: str): logger.info(f"Results have been cached for {logName}") balanced_hashes = await get_balanced_hashes(sorted_ranked_files, config) - results = [] for hash in sorted_ranked_files: for resolution in balanced_hashes: diff --git a/comet/utils/general.py b/comet/utils/general.py index 1d28ac7..63f2449 100644 --- a/comet/utils/general.py +++ b/comet/utils/general.py @@ -199,14 +199,13 @@ async def get_balanced_hashes(hashes: dict, config: dict): return balanced_hashes -async def check_info_hash(debrid_api_key: str, hash: str): +async def check_info_hash(session: aiohttp.ClientSession, debrid_api_key: str, hash: str): try: - async with aiohttp.ClientSession(headers={ + response = await session.get(f"https://api.real-debrid.com/rest/1.0/torrents/instantAvailability/{hash}", headers={ "Authorization": f"Bearer {debrid_api_key}" - }) as session: - response = await session.get(f"https://api.real-debrid.com/rest/1.0/torrents/instantAvailability/{hash}") + }) - return response + return response except Exception as e: logger.warning(f"Exception while checking info hash with Real Debrid for {hash}: {e}")