fix: use US iTunes genre to avoid Japanese-localized genre names
JP store returns localized genres (e.g. イージーリスニング instead of Easy Listening). Fetch JP and US in parallel, use JP match for title/album/artwork but always take genre from US result so genre is always in English/Western characters. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
67f4be272a
commit
760d8d5e1f
1 file changed
+7
-8
@@ -112,15 +112,14 @@ async function lookupItunesTrackMeta(artist, title) {
|
|||||||
);
|
);
|
||||||
const titleOnlyMatch = results => results.find(t => normalizeTitle(t.trackName) === normT);
|
const titleOnlyMatch = results => results.find(t => normalizeTitle(t.trackName) === normT);
|
||||||
|
|
||||||
// Strategy: JP strict → US strict → US title-only (never JP title-only to avoid
|
// Fetch both in parallel — JP for correct Japanese titles/artwork, US for English genre names
|
||||||
// false positives where JP returns a different Japanese song with the same English title)
|
const [jpResults, usResults] = await Promise.all([fetchItunes('jp'), fetchItunes('us')]);
|
||||||
const jpResults = await fetchItunes('jp');
|
|
||||||
let match = strictMatch(jpResults);
|
let match = strictMatch(jpResults);
|
||||||
if (!match) {
|
let usMatch = strictMatch(usResults) || titleOnlyMatch(usResults);
|
||||||
const usResults = await fetchItunes('us');
|
if (!match) match = usMatch;
|
||||||
match = strictMatch(usResults) || titleOnlyMatch(usResults);
|
|
||||||
}
|
|
||||||
if (!match) return {};
|
if (!match) return {};
|
||||||
|
// JP genre names are localized (e.g. イージーリスニング); always prefer US genre
|
||||||
|
const genre = (usMatch || match).primaryGenreName;
|
||||||
return {
|
return {
|
||||||
album: match.collectionName || '',
|
album: match.collectionName || '',
|
||||||
year: match.releaseDate ? new Date(match.releaseDate).getFullYear() : undefined,
|
year: match.releaseDate ? new Date(match.releaseDate).getFullYear() : undefined,
|
||||||
@@ -128,7 +127,7 @@ async function lookupItunesTrackMeta(artist, title) {
|
|||||||
totalTracks: match.trackCount || undefined,
|
totalTracks: match.trackCount || undefined,
|
||||||
discNum: match.discNumber || undefined,
|
discNum: match.discNumber || undefined,
|
||||||
discTotal: match.discCount || undefined,
|
discTotal: match.discCount || undefined,
|
||||||
genre: match.primaryGenreName || undefined,
|
genre: genre || undefined,
|
||||||
artworkUrl: (match.artworkUrl100 || '').replace('100x100bb', '1000x1000bb'),
|
artworkUrl: (match.artworkUrl100 || '').replace('100x100bb', '1000x1000bb'),
|
||||||
durationMs: match.trackTimeMillis || undefined,
|
durationMs: match.trackTimeMillis || undefined,
|
||||||
itunesArtistName: match.artistName || undefined,
|
itunesArtistName: match.artistName || undefined,
|
||||||
|
|||||||
Reference in new issue
Block a user