diff --git a/src/views.js b/src/views.js index 24bb497..4db3fdf 100644 --- a/src/views.js +++ b/src/views.js @@ -369,11 +369,19 @@ export async function loadArtistDetail(artist) { hasND ? api('getTopSongs', `&artist=${encodeURIComponent(artist.name)}&count=10`) : Promise.resolve(null), knownItunes ? Promise.resolve([{ artistId: knownItunes }]) - : itunesSearch(artist.name, 'musicArtist', 1), + : itunesSearch(artist.name, 'musicArtist', 5), ]); - const itunesArtistId = knownItunes - ?? (iArtistRes.status === 'fulfilled' ? (iArtistRes.value[0]?.artistId ?? null) : null); + // Verify name match — iTunes ranks by popularity, so "WRLD Tunes" would otherwise + // return "Juice WRLD" first. Require all query words to appear in the iTunes name. + const _normWords = s => new Set((s || '').toLowerCase().replace(/[^a-z0-9]/g, ' ').split(/\s+/).filter(Boolean)); + const _queryWords = _normWords(artist.name); + const iArtistResults = iArtistRes.status === 'fulfilled' ? (iArtistRes.value || []) : []; + const iArtistMatch = iArtistResults.find(r => { + const rw = _normWords(r.artistName); + return _queryWords.size > 0 && [..._queryWords].every(w => rw.has(w)); + }); + const itunesArtistId = knownItunes ?? iArtistMatch?.artistId ?? null; // Phase 2 — iTunes data (needs artist ID) const [iAlbumsRes, iTracksRes] = itunesArtistId