From fca3e641dc7fc25ffdb7a94067dfe7606b70da78 Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Fri, 12 Dec 2025 21:19:29 -0800 Subject: [PATCH] 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. --- webui/static/script.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/webui/static/script.js b/webui/static/script.js index ffec7e8a..86513f85 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -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