feat: implement librespot-powered search

This commit is contained in:
Xoconoch
2025-08-26 22:09:07 -06:00
parent c38f10957c
commit 6c795d8d92
3 changed files with 76 additions and 3 deletions

View File

@@ -482,9 +482,22 @@ class Spo:
@classmethod
def search(cls, query, search_type='track', limit=10, country: Optional[str] = None, locale: Optional[str] = None, catalogue: Optional[str] = None, image_size: Optional[str] = None, client_id=None, client_secret=None):
cls.__check_initialized()
# Map simple type value; librespot returns a combined JSON-like response
# Preferred path: use LibrespotClient for consistent defaults and options
if cls.__client is not None:
res = cls.__client.search(
query=query,
limit=limit,
country=country or cls.__get_session_country_code(),
locale=locale,
catalogue=catalogue,
image_size=image_size,
)
# Optionally filter by type if requested (best-effort; librespot returns mixed)
if search_type and isinstance(res, dict) and search_type in res:
return {search_type: res.get(search_type)}
return res
# Fallback: direct SearchManager
req = SearchManager.SearchRequest(query).set_limit(limit)
# Country precedence: explicit country > session country
if country:
req.set_country(country)
else:
@@ -498,4 +511,6 @@ class Spo:
if image_size:
req.set_image_size(image_size)
res = cls.__session.search().request(req) # type: ignore[union-attr]
if search_type and isinstance(res, dict) and search_type in res:
return {search_type: res.get(search_type)}
return res