88from typing import Any
99from urllib .parse import quote
1010
11- from aiohttp import ClientSession
11+ from aiohttp import ClientSession , ClientTimeout
1212
1313from stream .core .config_manager import Config
1414from stream .helpers .hoaders import hoaders_big_cover_url , hoaders_cover_info
@@ -192,7 +192,7 @@ async def spotify_album_cover_url(*, artist: str, album: str, year: int | None =
192192 _dbg (f"[cover] spotify_album query={ q !r} " )
193193 url = f"https://api.spotify.com/v1/search?q={ quote (q )} &type=album&limit=5"
194194 async with _SPOTIFY_SEM :
195- async with ClientSession () as session :
195+ async with ClientSession (timeout = ClientTimeout ( total = 5.0 ) ) as session :
196196 async with session .get (url , headers = headers ) as resp :
197197 payload = await _json_or_none (resp , label = "spotify_album" )
198198 if payload is None :
@@ -290,7 +290,7 @@ async def spotify_best_track(*, title: str, artist: str, album: str = "", year:
290290 _dbg (f"[cover] spotify_track query={ q !r} " )
291291 url = f"https://api.spotify.com/v1/search?q={ quote (q )} &type=track&limit=5"
292292 async with _SPOTIFY_SEM :
293- async with ClientSession () as session :
293+ async with ClientSession (timeout = ClientTimeout ( total = 5.0 ) ) as session :
294294 async with session .get (url , headers = headers ) as resp :
295295 payload = await _json_or_none (resp , label = "spotify_track" )
296296 if payload is None :
@@ -399,6 +399,7 @@ async def apple_cover_url(*, title: str, artist: str, album: str = "", year: int
399399 best_art = None
400400 best_score = - 1
401401
402+ terms = terms [:2 ]
402403 seen : set [str ] = set ()
403404 for term in terms :
404405 k = (term or "" ).strip ().casefold ()
@@ -414,8 +415,8 @@ async def apple_cover_url(*, title: str, artist: str, album: str = "", year: int
414415
415416 async with _APPLE_SEM :
416417 try :
417- async with ClientSession () as session :
418- async with session .get (url , timeout = 8 ) as resp :
418+ async with ClientSession (timeout = ClientTimeout ( total = 5.0 ) ) as session :
419+ async with session .get (url ) as resp :
419420 if resp .status in (403 , 429 ):
420421 _dbg (f"[cover] apple rate limited/blocked status={ resp .status } , backing off for 60s" )
421422 _APPLE_BACKOFF_UNTIL = time .time () + 60.0
@@ -476,6 +477,7 @@ async def deezer_cover_url(*, title: str, artist: str, album: str = "", year: in
476477 if t :
477478 queries .append (f"{ t } { int (year )} " .strip ())
478479
480+ queries = queries [:2 ]
479481 seen : set [str ] = set ()
480482 for q in queries :
481483 k = (q or "" ).strip ().casefold ()
@@ -485,14 +487,18 @@ async def deezer_cover_url(*, title: str, artist: str, album: str = "", year: in
485487
486488 url = f"https://api.deezer.com/search?q={ quote (q )} &limit=3"
487489 _dbg (f"[cover] deezer query={ q !r} " )
488- async with ClientSession () as session :
489- async with session .get (url ) as resp :
490- payload = await _json_or_none (resp , label = "deezer" )
491- if payload is None :
492- continue
493- if resp .status != 200 :
494- _dbg (f"[cover] deezer error status={ resp .status } body={ str (payload )[:300 ]!r} " )
495- continue
490+ try :
491+ async with ClientSession (timeout = ClientTimeout (total = 5.0 )) as session :
492+ async with session .get (url ) as resp :
493+ payload = await _json_or_none (resp , label = "deezer" )
494+ if payload is None :
495+ continue
496+ if resp .status != 200 :
497+ _dbg (f"[cover] deezer error status={ resp .status } body={ str (payload )[:300 ]!r} " )
498+ continue
499+ except Exception as e :
500+ _dbg (f"[cover] deezer request failed: { e } " )
501+ continue
496502
497503 data = (payload or {}).get ("data" ) or []
498504 if not isinstance (data , list ) or not data :
@@ -1053,8 +1059,6 @@ async def youtube_cover_search(
10531059
10541060 for q in queries :
10551061 candidates = await _search_youtube_innertube (q )
1056- if not candidates :
1057- candidates = await asyncio .to_thread (_search_youtube_ytdlp_sync , q )
10581062
10591063 for cand in candidates :
10601064 vid = cand .get ("video_id" )
0 commit comments