The global handle in web_server.py was named soulseek_client for historical reasons but the type has long been DownloadOrchestrator, not SoulseekClient. Renamed the global plus every parameter/attribute that carried the legacy name. - web_server.py: global var renamed; all 99 references updated. - api/, core/downloads/*, core/search/*, core/streaming/*, services/sync_service.py: parameter names, dataclass fields, and init() arg names renamed. - Test fixtures (CandidatesDeps, MasterDeps, SearchDeps, etc.) and the _build_deps helpers updated accordingly. The core.soulseek_client module path and SoulseekClient class name (the actual soulseek-only client) are unchanged — only the orchestrator handle renamed. Module imports of TrackResult/AlbumResult/DownloadStatus from core.soulseek_client preserved.
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
"""Basic Soulseek file search — flat list of file results sorted by quality.
|
|
|
|
Used by the Soulseek source icon in the unified search UI and by direct
|
|
/api/search calls. Synchronous wrapper around the async soulseek client.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Callable
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def run_basic_soulseek_search(
|
|
query: str,
|
|
download_orchestrator,
|
|
run_async: Callable,
|
|
) -> list[dict]:
|
|
"""Search Soulseek for `query`, normalize albums + tracks to one sorted list.
|
|
|
|
Returns dicts with `result_type` set to "album" or "track" and sorted by
|
|
`quality_score` descending. Empty list on any failure (caller logs).
|
|
"""
|
|
tracks, albums = run_async(download_orchestrator.search(query))
|
|
|
|
processed_albums = []
|
|
for album in albums:
|
|
album_dict = album.__dict__.copy()
|
|
album_dict['tracks'] = [track.__dict__ for track in album.tracks]
|
|
album_dict['result_type'] = 'album'
|
|
processed_albums.append(album_dict)
|
|
|
|
processed_tracks = []
|
|
for track in tracks:
|
|
track_dict = track.__dict__.copy()
|
|
track_dict['result_type'] = 'track'
|
|
processed_tracks.append(track_dict)
|
|
|
|
return sorted(
|
|
processed_albums + processed_tracks,
|
|
key=lambda x: x.get('quality_score', 0),
|
|
reverse=True,
|
|
)
|