From 7d0df2b9ed3c5fe7a3524b96cdeba227d228fd76 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Mon, 16 Mar 2026 19:35:26 -0700 Subject: [PATCH] Fix discover page Deezer source support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- core/personalized_playlists.py | 14 ++++++++++---- database/music_database.py | 2 ++ web_server.py | 10 +++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/core/personalized_playlists.py b/core/personalized_playlists.py index 7352214..fe21ccd 100644 --- a/core/personalized_playlists.py +++ b/core/personalized_playlists.py @@ -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 = [] diff --git a/database/music_database.py b/database/music_database.py index 8e6ac1b..f1d7eec 100644 --- a/database/music_database.py +++ b/database/music_database.py @@ -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'], diff --git a/web_server.py b/web_server.py index 131fa9d..2ed4694 100644 --- a/web_server.py +++ b/web_server.py @@ -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()