fix: verify iTunes artist name matches query before using result

iTunes ranks by popularity, so searching "WRLD Tunes" returned Juice WRLD
first. Now fetches 5 results and picks the first where all query words
appear in the iTunes artist name, preventing false-positive matches.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-24 23:36:46 +02:00
1 parent 36b09856ed
commit 88533b8835
1 file changed
+11 -3
+11 -3
View File
@@ -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