fix: ie-totaltracks element id + JP-strict/US-fallback iTunes matching
Prevent false Japanese matches by never using JP title-only fallback. Strategy: JP strict → US strict → US title-only so niche Western tracks still resolve but same-English-title Japanese songs don't pollute results. Also fix JS error in autofillItunes: ie-total → ie-totaltracks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
21159ad2c5
commit
67f4be272a
2 files changed
+16
-12
No files matched your search
+15
-11
@@ -103,19 +103,23 @@ async function lookupItunesTrackMeta(artist, title) {
|
||||
res.on('end', () => { try { resolve(JSON.parse(d).results || []); } catch { reject(new Error('parse')); } });
|
||||
}).on('error', reject);
|
||||
});
|
||||
let results = await fetchItunes('jp');
|
||||
if (!results.length) results = await fetchItunes('us');
|
||||
const normT = normalizeTitle(title);
|
||||
const normA = (artist || '').toLowerCase().trim();
|
||||
const normT = normalizeTitle(title);
|
||||
const normA = (searchArtist || '').toLowerCase().trim();
|
||||
// Split by space OR comma/semicolon/slash so "VXLLAIN, iGRES" → "vxllain" not "vxllain,"
|
||||
const firstWord = s => (s || '').toLowerCase().split(/[\s,;/]/)[0];
|
||||
// Prefer strict match (title + first-word artist), fall back to title-only.
|
||||
// Title-only fallback handles cases where kuromoji gave a wrong artist romanization
|
||||
// (e.g. "Terui Jun Sei" vs iTunes "Yoshimasa Terui" — different first word).
|
||||
const match = results.find(t =>
|
||||
normalizeTitle(t.trackName) === normT &&
|
||||
firstWord(t.artistName) === firstWord(normA)
|
||||
) || results.find(t => normalizeTitle(t.trackName) === normT);
|
||||
const strictMatch = results => results.find(t =>
|
||||
normalizeTitle(t.trackName) === normT && firstWord(t.artistName) === firstWord(normA)
|
||||
);
|
||||
const titleOnlyMatch = results => results.find(t => normalizeTitle(t.trackName) === normT);
|
||||
|
||||
// Strategy: JP strict → US strict → US title-only (never JP title-only to avoid
|
||||
// false positives where JP returns a different Japanese song with the same English title)
|
||||
const jpResults = await fetchItunes('jp');
|
||||
let match = strictMatch(jpResults);
|
||||
if (!match) {
|
||||
const usResults = await fetchItunes('us');
|
||||
match = strictMatch(usResults) || titleOnlyMatch(usResults);
|
||||
}
|
||||
if (!match) return {};
|
||||
return {
|
||||
album: match.collectionName || '',
|
||||
|
||||
Reference in new issue
Block a user