fix: romaji for album names + Japanese playlist track matching

- ytdlp.js + novasonic-server.js: apply romajiForStorage to album tag
  and folder/rename paths (was only applied to artist/title before)
- ui.js: _createNdPlaylist falls back to romaji index for Japanese titles
  since Navidrome search3 doesn't index Japanese text properly

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-25 00:36:16 +02:00
1 parent 88533b8835
commit 392da7e021
3 files changed
+23 -9

No files matched your search

+14 -3
View File
@@ -1,6 +1,6 @@
import { S } from './state.js';
import { esc, formatDur, toast } from './utils.js';
import { api, coverUrl, ndAuth } from './api.js';
import { api, coverUrl, ndAuth, fetchRomajiIndex } from './api.js';
import { THEMES, applyTheme, getCurrentThemeId } from './themes.js';
// Circular imports — safe (only used inside function bodies)
import { playQueue, dlSongLocal, toggleStar, togglePlay, renderQueue, syncNpStar, updateStarBtn, npToggleStar, playCurrent, _syncNpDirect, setPlayIcon, nativeInsertAt } from './player.js';
@@ -560,6 +560,11 @@ async function _createNdPlaylist(tracks, name) {
const norm = s => s?.toLowerCase().trim() || '';
// Strip non-word, non-space chars for loose artist first-word comparison
const normA = s => norm(s).replace(/[^\w\s]/g, '');
const JP_RE = /[぀-ヿ一-鿿]/;
// Pre-fetch romaji index once if any track has Japanese chars — Navidrome search3
// doesn't handle Japanese text, so we need the index as a fallback.
const hasJp = tracks.some(t => JP_RE.test(t.trackName) || JP_RE.test(t.artistName));
const romajiIdx = hasJp ? await fetchRomajiIndex().catch(() => null) : null;
for (const t of tracks) {
if (!t.trackName) continue;
const missingLabel = t.artistName ? t.artistName + ' – ' + t.trackName : t.trackName;
@@ -579,8 +584,14 @@ async function _createNdPlaylist(tracks, name) {
const firstWord = s => normA(s).split(/\s+/)[0];
const titleMatch = s => norm(s.title) === norm(t.trackName);
const artistMatch = s => firstWord(s.artist) === firstWord(firstArtist || t.artistName);
const match = songs.find(s => titleMatch(s) && artistMatch(s))
|| songs.find(s => titleMatch(s));
let match = songs.find(s => titleMatch(s) && artistMatch(s))
|| songs.find(s => titleMatch(s));
// Fallback: search romaji index by original Japanese title
// (Navidrome search3 doesn't index Japanese text properly)
if (!match && romajiIdx && JP_RE.test(t.trackName)) {
const jpEntry = romajiIdx.find(e => norm(e.title) === norm(t.trackName));
if (jpEntry) match = { id: jpEntry.id };
}
if (match) songIds.push(match.id);
else missing.push(missingLabel);
} catch { missing.push(missingLabel); }