fix: aiohttp max number of simultaneous connections

This commit is contained in:
Goldy
2024-07-03 18:08:50 +02:00
parent 336a015732
commit 9309e15a12
2 changed files with 6 additions and 8 deletions
+2 -3
View File
@@ -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:
+4 -5
View File
@@ -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}")