Improve artist name extraction in wishlist selection
Enhanced the logic for extracting artist name and ID to handle both object and string formats from Spotify API and sanitized data. Added fallbacks to ensure artist information is correctly retrieved from multiple possible data structures.
This commit is contained in:
parent
4587022877
commit
fca3e641dc
1 changed files with 21 additions and 2 deletions
|
|
@ -5364,8 +5364,27 @@ async function selectWishlistCategory(category) {
|
|||
}
|
||||
|
||||
const albumName = spotifyData?.album?.name || 'Unknown Album';
|
||||
const artistName = spotifyData?.artists?.[0]?.name || 'Unknown Artist';
|
||||
const artistId = spotifyData?.artists?.[0]?.id || null;
|
||||
|
||||
// Handle both object format {name: '...'} and sanitized string format
|
||||
let artistName = 'Unknown Artist';
|
||||
let artistId = null;
|
||||
if (spotifyData?.artists?.[0]?.name) {
|
||||
// Object format from Spotify API
|
||||
artistName = spotifyData.artists[0].name;
|
||||
artistId = spotifyData.artists[0].id;
|
||||
} else if (spotifyData?.artists?.[0] && typeof spotifyData.artists[0] === 'string') {
|
||||
// Sanitized string format
|
||||
artistName = spotifyData.artists[0];
|
||||
} else if (Array.isArray(track.artists) && track.artists.length > 0) {
|
||||
// Fallback to track.artists
|
||||
if (typeof track.artists[0] === 'string') {
|
||||
artistName = track.artists[0];
|
||||
} else if (track.artists[0]?.name) {
|
||||
artistName = track.artists[0].name;
|
||||
artistId = track.artists[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
const albumImage = spotifyData?.album?.images?.[0]?.url || '';
|
||||
|
||||
// Use album ID if available, otherwise create unique key from album + artist
|
||||
|
|
|
|||
Loading…
Reference in a new issue