fix(ui): playlist match - use first artist only, strip punctuation, increase songCount

"Kløn, Renzyx" → search with "Kløn Alone", compare "kløn" == "kløn" (not "kløn,")
songCount raised to 20 so generic titles like "Alone" have better recall.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-02 12:35:19 +02:00
1 parent 9ca6e79b7b
commit 10a85e0497
1 file changed
+7 -4
+7 -4
View File
@@ -357,13 +357,16 @@ async function _createNdPlaylist(tracks, name) {
if (!t.trackName) continue; if (!t.trackName) continue;
const missingLabel = t.artistName ? `${t.artistName} – ${t.trackName}` : t.trackName; const missingLabel = t.artistName ? `${t.artistName} – ${t.trackName}` : t.trackName;
try { try {
// Search with artist+title first for precision, fall back to title-only with more results // Use first artist only for search to avoid comma/multi-artist confusion
const artistQuery = t.artistName ? `${t.artistName} ${t.trackName}` : t.trackName; const firstArtist = t.artistName ? t.artistName.split(/[,/•]/)[0].trim() : '';
const r = await api('search3', `&query=${encodeURIComponent(artistQuery)}&songCount=10&albumCount=0&artistCount=0`); const artistQuery = firstArtist ? `${firstArtist} ${t.trackName}` : t.trackName;
const r = await api('search3', `&query=${encodeURIComponent(artistQuery)}&songCount=20&albumCount=0&artistCount=0`);
const songs = r.searchResult3?.song || []; const songs = r.searchResult3?.song || [];
// Strip trailing punctuation from first word so "Kløn," matches "Kløn"
const firstWord = s => norm(s).split(/[\s,/•]+/)[0].replace(/\W+$/, '');
const match = songs.find(s => const match = songs.find(s =>
norm(s.title) === norm(t.trackName) && norm(s.title) === norm(t.trackName) &&
norm(s.artist).split(' ')[0] === norm(t.artistName).split(' ')[0] firstWord(s.artist) === firstWord(firstArtist || t.artistName)
) || songs.find(s => norm(s.title) === norm(t.trackName)); ) || songs.find(s => norm(s.title) === norm(t.trackName));
if (match) songIds.push(match.id); if (match) songIds.push(match.id);
else missing.push(missingLabel); else missing.push(missingLabel);