Fix discover page Deezer source support

- personalized_playlists._get_active_source() now returns 'deezer' when
  configured instead of always falling back to 'itunes'
- Add deezer_track_id to _build_track_dict() for discovery pool tracks
- Include album_deezer_id and artist_deezer_id in get_discovery_recent_albums()
  response — fixes "No deezer album ID available" error when clicking cards
- Skip Spotify library section entirely when Spotify is not authenticated
pull/253/head
Broque Thomas 4 weeks ago
parent 46d3309835
commit 7d0df2b9ed

@ -103,12 +103,16 @@ class PersonalizedPlaylistsService:
def _get_active_source(self) -> str:
"""
Determine which music source is active for discovery.
Returns 'spotify' if Spotify is authenticated, 'itunes' otherwise.
Returns 'spotify' if Spotify is authenticated, otherwise the configured fallback ('itunes' or 'deezer').
"""
if self.spotify_client and hasattr(self.spotify_client, 'is_spotify_authenticated'):
if self.spotify_client.is_spotify_authenticated():
return 'spotify'
return 'itunes'
try:
from config.settings import config_manager
return config_manager.get('metadata.fallback_source', 'itunes') or 'itunes'
except Exception:
return 'itunes'
def _build_track_dict(self, row, source: str) -> Dict:
"""Build a standardized track dictionary from a database row."""
@ -124,9 +128,10 @@ class PersonalizedPlaylistsService:
track_data = None
return {
'track_id': row.get('spotify_track_id') or row.get('itunes_track_id'),
'track_id': row.get('spotify_track_id') or row.get('itunes_track_id') or row.get('deezer_track_id'),
'spotify_track_id': row.get('spotify_track_id'),
'itunes_track_id': row.get('itunes_track_id'),
'deezer_track_id': row.get('deezer_track_id'),
'track_name': row.get('track_name', 'Unknown'),
'artist_name': row.get('artist_name', 'Unknown'),
'album_name': row.get('album_name', 'Unknown'),
@ -872,7 +877,8 @@ class PersonalizedPlaylistsService:
return {'tracks': [], 'error': 'Must provide 1-5 seed artists'}
use_spotify = self.spotify_client and self.spotify_client.sp
logger.info(f"Building custom playlist from {len(seed_artist_ids)} seed artists (source: {'spotify' if use_spotify else 'itunes'})")
active_source = 'spotify' if use_spotify else self._get_active_source()
logger.info(f"Building custom playlist from {len(seed_artist_ids)} seed artists (source: {active_source})")
# Step 1: Get similar artists for each seed
all_similar_artists = []

@ -6516,10 +6516,12 @@ class MusicDatabase:
return [{
'album_spotify_id': row['album_spotify_id'],
'album_itunes_id': row['album_itunes_id'] if 'album_itunes_id' in row_keys else None,
'album_deezer_id': row['album_deezer_id'] if 'album_deezer_id' in row_keys else None,
'album_name': row['album_name'],
'artist_name': row['artist_name'],
'artist_spotify_id': row['artist_spotify_id'],
'artist_itunes_id': row['artist_itunes_id'] if 'artist_itunes_id' in row_keys else None,
'artist_deezer_id': row['artist_deezer_id'] if 'artist_deezer_id' in row_keys else None,
'album_cover_url': row['album_cover_url'],
'release_date': row['release_date'],
'album_type': row['album_type'],

@ -32453,8 +32453,16 @@ def enrich_similar_artists():
@app.route('/api/discover/spotify-library', methods=['GET'])
def get_spotify_library():
"""Get cached Spotify library albums with ownership status"""
"""Get cached Spotify library albums with ownership status. Only available when Spotify is authenticated."""
try:
# Skip entirely if Spotify is not the active source
if not spotify_client or not spotify_client.is_spotify_authenticated():
return jsonify({
"success": True, "albums": [], "total": 0,
"offset": 0, "limit": 0,
"stats": {"total": 0, "owned": 0, "missing": 0}
})
database = get_database()
profile_id = get_current_profile_id()

Loading…
Cancel
Save