diff --git a/api/search.py b/api/search.py index 321f144d..48a237c7 100644 --- a/api/search.py +++ b/api/search.py @@ -42,16 +42,17 @@ def register_routes(bp): pass spotify = ctx.get("spotify_client") - if source in ("spotify", "auto") and spotify and spotify.is_authenticated(): + from core.metadata_service import get_primary_source, get_primary_client + primary = get_primary_source() + if source in ("spotify", "auto") and primary == 'spotify' and spotify and spotify.is_spotify_authenticated(): results = spotify.search_tracks(query, limit=limit) if results: tracks = [_serialize_track(t) for t in results] return api_success({"tracks": tracks, "source": "spotify"}) if source in ("itunes", "deezer", "auto"): - from core.metadata_service import _create_fallback_client, _get_configured_fallback_source - fallback = _create_fallback_client() - fallback_source = _get_configured_fallback_source() + fallback = get_primary_client() + fallback_source = get_primary_source() results = fallback.search_tracks(query, limit=limit) if results: tracks = [_serialize_track(t) for t in results] @@ -78,7 +79,9 @@ def register_routes(bp): try: ctx = current_app.soulsync spotify = ctx.get("spotify_client") - if spotify and spotify.is_authenticated(): + from core.metadata_service import get_primary_source, get_primary_client + primary = get_primary_source() + if primary == 'spotify' and spotify and spotify.is_spotify_authenticated(): results = spotify.search_albums(query, limit=limit) if results: return api_success({ @@ -86,9 +89,8 @@ def register_routes(bp): "source": "spotify", }) - from core.metadata_service import _create_fallback_client, _get_configured_fallback_source - fallback = _create_fallback_client() - fallback_source = _get_configured_fallback_source() + fallback = get_primary_client() + fallback_source = get_primary_source() results = fallback.search_albums(query, limit=limit) return api_success({ "albums": [_serialize_album(a) for a in results] if results else [], @@ -114,7 +116,9 @@ def register_routes(bp): try: ctx = current_app.soulsync spotify = ctx.get("spotify_client") - if spotify and spotify.is_authenticated(): + from core.metadata_service import get_primary_source, get_primary_client + primary = get_primary_source() + if primary == 'spotify' and spotify and spotify.is_spotify_authenticated(): results = spotify.search_artists(query, limit=limit) if results: return api_success({ @@ -122,9 +126,8 @@ def register_routes(bp): "source": "spotify", }) - from core.metadata_service import _create_fallback_client, _get_configured_fallback_source - fallback = _create_fallback_client() - fallback_source = _get_configured_fallback_source() + fallback = get_primary_client() + fallback_source = get_primary_source() results = fallback.search_artists(query, limit=limit) return api_success({ "artists": [_serialize_artist(a) for a in results] if results else [], diff --git a/core/seasonal_discovery.py b/core/seasonal_discovery.py index e1d31e21..e7f5d4ac 100644 --- a/core/seasonal_discovery.py +++ b/core/seasonal_discovery.py @@ -442,14 +442,14 @@ class SeasonalDiscoveryService: seasonal_albums = [] source = self._get_source() - use_spotify = self.spotify_client and self.spotify_client.is_authenticated() + use_spotify = (source == 'spotify') and self.spotify_client and self.spotify_client.is_spotify_authenticated() # IMPROVED: Sample 20 random watchlist artists (up from 10) for more variety sampled_artists = random.sample(watchlist_artists, min(20, len(watchlist_artists))) - from core.metadata_service import _create_fallback_client, _get_configured_fallback_source - fallback_client = _create_fallback_client() - fallback_source = _get_configured_fallback_source() + from core.metadata_service import get_primary_client, get_primary_source + fallback_client = get_primary_client() + fallback_source = get_primary_source() for artist in sampled_artists: try: @@ -507,7 +507,7 @@ class SeasonalDiscoveryService: config = SEASONAL_CONFIG[season_key] keywords = config['keywords'] source = self._get_source() - use_spotify = self.spotify_client and self.spotify_client.is_authenticated() + use_spotify = (source == 'spotify') and self.spotify_client and self.spotify_client.is_spotify_authenticated() seasonal_albums = [] seen_album_ids = set() @@ -767,10 +767,10 @@ class SeasonalDiscoveryService: # Get tracks from seasonal albums (filtered by source) seasonal_albums = self.get_seasonal_albums(season_key, limit=50, source=source) - use_spotify = self.spotify_client and self.spotify_client.is_authenticated() + use_spotify = (source == 'spotify') and self.spotify_client and self.spotify_client.is_spotify_authenticated() if not use_spotify: - from core.metadata_service import _create_fallback_client - fallback_client = _create_fallback_client() + from core.metadata_service import get_primary_client + fallback_client = get_primary_client() for album in seasonal_albums: try: