diff --git a/core/spotify_client.py b/core/spotify_client.py index 776371cc..3f3ecf1c 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -145,14 +145,15 @@ class Album: album_type: str image_url: Optional[str] = None external_urls: Optional[Dict[str, str]] = None - + artist_ids: Optional[List[str]] = None + @classmethod def from_spotify_album(cls, album_data: Dict[str, Any]) -> 'Album': # Get the largest image URL if available image_url = None if album_data.get('images') and len(album_data['images']) > 0: image_url = album_data['images'][0]['url'] - + return cls( id=album_data['id'], name=album_data['name'], @@ -161,7 +162,8 @@ class Album: total_tracks=album_data.get('total_tracks', 0), album_type=album_data.get('album_type', 'album'), image_url=image_url, - external_urls=album_data.get('external_urls') + external_urls=album_data.get('external_urls'), + artist_ids=[artist['id'] for artist in album_data['artists']] ) @dataclass diff --git a/web_server.py b/web_server.py index 918d6b30..614b4ae1 100644 --- a/web_server.py +++ b/web_server.py @@ -5462,17 +5462,10 @@ def get_artist_discography(artist_id): continue seen_albums.add(album.id) - # Handle artist matching for both Spotify (objects) and iTunes (strings) formats - if hasattr(album, 'artists') and album.artists: - first_artist = album.artists[0] - # Check if artists are objects (Spotify) or strings (iTunes) - if hasattr(first_artist, 'id'): - # Spotify format: artist is an object with .id and .name - primary_artist_id = first_artist.id - # Skip if the primary artist doesn't match our requested artist - if primary_artist_id and primary_artist_id != artist_id: - continue - # iTunes format: artist is a string, can't verify ID match so include all + # Skip albums where this artist isn't the primary (first-listed) artist + if hasattr(album, 'artist_ids') and album.artist_ids: + if album.artist_ids[0] != artist_id: + continue album_data = { "id": album.id, @@ -25336,6 +25329,10 @@ def get_spotify_artist_discography(artist_name): singles = [] for album in all_albums: + # Skip albums where this artist isn't the primary (first-listed) artist + if album.artist_ids and album.artist_ids[0] != spotify_artist_id: + continue + # Use the Album object properties track_count = album.total_tracks