This commit is contained in:
Xoconoch
2025-07-26 19:57:09 -06:00
parent 523eeed06b
commit c92821ee48
3 changed files with 46 additions and 23 deletions

View File

@@ -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.
@@ -256,7 +256,7 @@ def get_spotfy_info(spotify_id: str, spotify_type: str, limit: Optional[int] = N
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}")

View File

@@ -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;
}

View File

@@ -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 {