fix: repair Japanese song download pipeline

Five separate root causes fixed:

1. buildTitleKeywords (ytdlp.js): For Japanese titles \w strips all
   kana/kanji leaving no keywords. Now uses the first whitespace-
   delimited segment as a literal regex keyword so --match-filter
   title ~= requires the YTM video to contain the Japanese text.

2. Tokenizer wait (ytdlp.js): If kuromoji hasn't finished loading when
   a Japanese download starts, romajiForStorage returns the original
   Japanese text unchanged — producing Japanese folder/filenames and
   skipping sort tags. Now waits up to 30 s for the tokenizer.

3. titleOnlyMatch guard (metadata.js): iTunes titleOnlyMatch (no artist
   check) was used as a fallback for all searches. For Japanese
   titles/artists this matched wrong US songs with identical titles
   (common in anime OSTs). Now titleOnlyMatch is skipped when the
   search title or artist contains Japanese characters.

4. squid.js rawArtist: rawArtist was not in squid's signature and
   never forwarded to embedMetadata, so Qobuz-downloaded J-Pop tracks
   stored the iTunes-resolved English name as artist instead of the
   Japanese original. Fixed by accepting and forwarding rawArtist.

5. squid.js romaji paths: Folder and filename used raw artist/title
   with no romaji conversion, creating Japanese-named paths
   inconsistent with the yt-dlp path. Now uses romajiForStorage same
   as ytdlp.js.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-29 01:40:46 +02:00
1 parent 52451f5086
commit 63ff8920bf
3 files changed
+45 -10

No files matched your search

+6 -1
View File
@@ -128,7 +128,12 @@ async function lookupItunesTrackMeta(artist, title) {
// Fetch both in parallel — JP for correct Japanese titles/artwork, US for English genre names
const [jpResults, usResults] = await Promise.all([fetchItunes('jp'), fetchItunes('us')]);
let match = strictMatch(jpResults);
let usMatch = strictMatch(usResults) || titleOnlyMatch(usResults);
// titleOnlyMatch (no artist check) is too permissive for Japanese titles/artists —
// common anime/OST titles exist on both JP and US stores under different artists.
// Only use it as a fallback when neither title nor artist contains Japanese characters.
const JP_RE = /[぀-ヿ㐀-䶿一-鿿]/;
const isJpSearch = JP_RE.test(normT) || JP_RE.test(normA);
let usMatch = strictMatch(usResults) || (!isJpSearch && titleOnlyMatch(usResults));
if (!match) match = usMatch;
if (!match) return {};
// JP genre names are localized (e.g. イージーリスニング); prefer US genre, map JP→EN as fallback