Fix remaining Spotify-first source selection in seasonal discovery and search API

Seasonal discovery had 3 use_spotify checks using is_authenticated()
(always True) instead of deriving from the configured source. Search API
(tracks, albums, artists) also defaulted to Spotify when authenticated.

All now check configured primary source first via get_primary_source().
This commit is contained in:
Broque Thomas 2026-04-10 12:47:16 -07:00
parent 498c22e7c3
commit 10a2766557
2 changed files with 23 additions and 20 deletions

View file

@ -42,16 +42,17 @@ def register_routes(bp):
pass pass
spotify = ctx.get("spotify_client") 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) results = spotify.search_tracks(query, limit=limit)
if results: if results:
tracks = [_serialize_track(t) for t in results] tracks = [_serialize_track(t) for t in results]
return api_success({"tracks": tracks, "source": "spotify"}) return api_success({"tracks": tracks, "source": "spotify"})
if source in ("itunes", "deezer", "auto"): if source in ("itunes", "deezer", "auto"):
from core.metadata_service import _create_fallback_client, _get_configured_fallback_source fallback = get_primary_client()
fallback = _create_fallback_client() fallback_source = get_primary_source()
fallback_source = _get_configured_fallback_source()
results = fallback.search_tracks(query, limit=limit) results = fallback.search_tracks(query, limit=limit)
if results: if results:
tracks = [_serialize_track(t) for t in results] tracks = [_serialize_track(t) for t in results]
@ -78,7 +79,9 @@ def register_routes(bp):
try: try:
ctx = current_app.soulsync ctx = current_app.soulsync
spotify = ctx.get("spotify_client") 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) results = spotify.search_albums(query, limit=limit)
if results: if results:
return api_success({ return api_success({
@ -86,9 +89,8 @@ def register_routes(bp):
"source": "spotify", "source": "spotify",
}) })
from core.metadata_service import _create_fallback_client, _get_configured_fallback_source fallback = get_primary_client()
fallback = _create_fallback_client() fallback_source = get_primary_source()
fallback_source = _get_configured_fallback_source()
results = fallback.search_albums(query, limit=limit) results = fallback.search_albums(query, limit=limit)
return api_success({ return api_success({
"albums": [_serialize_album(a) for a in results] if results else [], "albums": [_serialize_album(a) for a in results] if results else [],
@ -114,7 +116,9 @@ def register_routes(bp):
try: try:
ctx = current_app.soulsync ctx = current_app.soulsync
spotify = ctx.get("spotify_client") 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) results = spotify.search_artists(query, limit=limit)
if results: if results:
return api_success({ return api_success({
@ -122,9 +126,8 @@ def register_routes(bp):
"source": "spotify", "source": "spotify",
}) })
from core.metadata_service import _create_fallback_client, _get_configured_fallback_source fallback = get_primary_client()
fallback = _create_fallback_client() fallback_source = get_primary_source()
fallback_source = _get_configured_fallback_source()
results = fallback.search_artists(query, limit=limit) results = fallback.search_artists(query, limit=limit)
return api_success({ return api_success({
"artists": [_serialize_artist(a) for a in results] if results else [], "artists": [_serialize_artist(a) for a in results] if results else [],

View file

@ -442,14 +442,14 @@ class SeasonalDiscoveryService:
seasonal_albums = [] seasonal_albums = []
source = self._get_source() 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 # IMPROVED: Sample 20 random watchlist artists (up from 10) for more variety
sampled_artists = random.sample(watchlist_artists, min(20, len(watchlist_artists))) sampled_artists = random.sample(watchlist_artists, min(20, len(watchlist_artists)))
from core.metadata_service import _create_fallback_client, _get_configured_fallback_source from core.metadata_service import get_primary_client, get_primary_source
fallback_client = _create_fallback_client() fallback_client = get_primary_client()
fallback_source = _get_configured_fallback_source() fallback_source = get_primary_source()
for artist in sampled_artists: for artist in sampled_artists:
try: try:
@ -507,7 +507,7 @@ class SeasonalDiscoveryService:
config = SEASONAL_CONFIG[season_key] config = SEASONAL_CONFIG[season_key]
keywords = config['keywords'] keywords = config['keywords']
source = self._get_source() 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 = [] seasonal_albums = []
seen_album_ids = set() seen_album_ids = set()
@ -767,10 +767,10 @@ class SeasonalDiscoveryService:
# Get tracks from seasonal albums (filtered by source) # Get tracks from seasonal albums (filtered by source)
seasonal_albums = self.get_seasonal_albums(season_key, limit=50, source=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: if not use_spotify:
from core.metadata_service import _create_fallback_client from core.metadata_service import get_primary_client
fallback_client = _create_fallback_client() fallback_client = get_primary_client()
for album in seasonal_albums: for album in seasonal_albums:
try: try: