From c92821ee48f35dc4afcd6426e63e000de8158d8d Mon Sep 17 00:00:00 2001 From: Xoconoch Date: Sat, 26 Jul 2025 19:57:09 -0600 Subject: [PATCH] fixed #198 --- routes/utils/get_info.py | 28 +++++++++++++-------------- spotizerr-ui/src/routes/artist.tsx | 31 +++++++++++++++++++++--------- spotizerr-ui/src/types/spotify.ts | 10 ++++++++++ 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/routes/utils/get_info.py b/routes/utils/get_info.py index f24c481..00aeb7f 100644 --- a/routes/utils/get_info.py +++ b/routes/utils/get_info.py @@ -28,16 +28,16 @@ def _get_spotify_client(): current_time = time.time() - # Reinitialize client if it's been more than an hour or if client doesn't exist + # Reinitialize client if it's been more than an hour or if client doesn't exist if (_spotify_client is None or current_time - _last_client_init > _client_init_interval): client_id, client_secret = _get_global_spotify_api_creds() - if not client_id or not client_secret: - raise ValueError( - "Global Spotify API client_id or client_secret not configured in ./data/creds/search.json." - ) + if not client_id or not client_secret: + raise ValueError( + "Global Spotify API client_id or client_secret not configured in ./data/creds/search.json." + ) # Create new client _spotify_client = spotipy.Spotify( @@ -212,7 +212,7 @@ def check_playlist_updated(playlist_id: str, last_snapshot_id: str) -> bool: raise @_rate_limit_handler -def get_spotfy_info(spotify_id: str, spotify_type: str, limit: Optional[int] = None, offset: Optional[int] = None) -> Dict[str, Any]: +def get_spotify_info(spotify_id: str, spotify_type: str, limit: Optional[int] = None, offset: Optional[int] = None) -> Dict[str, Any]: """ Get info from Spotify API using Spotipy directly. Optimized to prevent rate limiting by using appropriate endpoints. @@ -231,21 +231,21 @@ def get_spotfy_info(spotify_id: str, spotify_type: str, limit: Optional[int] = N try: if spotify_type == "track": return client.track(spotify_id) - + elif spotify_type == "album": return client.album(spotify_id) - + elif spotify_type == "playlist": # Use optimized playlist fetching return get_playlist_full(spotify_id) - + elif spotify_type == "playlist_metadata": # Get only metadata for playlists return get_playlist_metadata(spotify_id) - + elif spotify_type == "artist": return client.artist(spotify_id) - + elif spotify_type == "artist_discography": # Get artist's albums with pagination albums = client.artist_albums( @@ -254,10 +254,10 @@ def get_spotfy_info(spotify_id: str, spotify_type: str, limit: Optional[int] = N offset=offset or 0 ) return albums - + elif spotify_type == "episode": - return client.episode(spotify_id) - + return client.episode(spotify_id) + else: raise ValueError(f"Unsupported Spotify type: {spotify_type}") diff --git a/spotizerr-ui/src/routes/artist.tsx b/spotizerr-ui/src/routes/artist.tsx index 4f57db7..3220477 100644 --- a/spotizerr-ui/src/routes/artist.tsx +++ b/spotizerr-ui/src/routes/artist.tsx @@ -27,20 +27,33 @@ export const Artist = () => { const fetchArtistData = async () => { if (!artistId) return; try { - const response = await apiClient.get<{ items: AlbumType[] }>(`/artist/info?id=${artistId}`); - const albumData = response.data; + const response = await apiClient.get(`/artist/info?id=${artistId}`); + const artistData = response.data; - if (albumData?.items && albumData.items.length > 0) { - const firstAlbum = albumData.items[0]; - if (firstAlbum.artists && firstAlbum.artists.length > 0) { - setArtist(firstAlbum.artists[0]); + // Check if we have artist data in the response + if (artistData?.id && artistData?.name) { + // Set artist info directly from the response + setArtist({ + id: artistData.id, + name: artistData.name, + images: artistData.images || [], + external_urls: artistData.external_urls || { spotify: "" }, + followers: artistData.followers || { total: 0 }, + genres: artistData.genres || [], + popularity: artistData.popularity || 0, + type: artistData.type || 'artist', + uri: artistData.uri || '' + }); + + // Check if we have albums data + if (artistData?.albums?.items && artistData.albums.items.length > 0) { + setAlbums(artistData.albums.items); } else { - setError("Could not determine artist from album data."); + setError("No albums found for this artist."); return; } - setAlbums(albumData.items); } else { - setError("No albums found for this artist."); + setError("Could not load artist data."); return; } diff --git a/spotizerr-ui/src/types/spotify.ts b/spotizerr-ui/src/types/spotify.ts index 79e6877..59e75b6 100644 --- a/spotizerr-ui/src/types/spotify.ts +++ b/spotizerr-ui/src/types/spotify.ts @@ -8,6 +8,16 @@ export interface ArtistType { id: string; name: string; images?: ImageType[]; + external_urls?: { + spotify: string; + }; + followers?: { + total: number; + }; + genres?: string[]; + popularity?: number; + type?: string; + uri?: string; } export interface TrackAlbumInfo {