refactor: remove LRCLIB fallback — handled by navidrome-lyrics-plugin
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b2f277ff7
commit
654cde6796
1 file changed
+3
-48
+3
-48
@@ -95,18 +95,6 @@ let _lyricsLoadToken = 0;
|
||||
|
||||
const LYRICS_LOOKAHEAD_MS = 200;
|
||||
|
||||
function _parseLrc(text) {
|
||||
let offsetMs = 0;
|
||||
const lines = [];
|
||||
for(const raw of text.split('\n')) {
|
||||
const offM = raw.match(/^\[offset:\s*([+-]?\d+)\s*\]/i);
|
||||
if(offM) { offsetMs = parseInt(offM[1]); continue; }
|
||||
const m = raw.match(/^\[(\d+):(\d+(?:\.\d+)?)\](.*)/);
|
||||
if(m) lines.push({ start: Math.round((parseInt(m[1])*60 + parseFloat(m[2]))*1000), value: m[3].trim() });
|
||||
}
|
||||
if(offsetMs) lines.forEach(l => l.start = Math.max(0, l.start + offsetMs));
|
||||
return lines.sort((a,b) => a.start - b.start).filter(l => l.value);
|
||||
}
|
||||
|
||||
function _renderSyncedLines(content, lines) {
|
||||
const top = document.createElement('div');
|
||||
@@ -138,53 +126,20 @@ async function _loadNpLyrics(songId) {
|
||||
content.innerHTML = '<div style="text-align:center;padding:60px 0;color:rgba(255,255,255,.3);font-size:14px">Lade Lyrics…</div>';
|
||||
|
||||
const token = ++_lyricsLoadToken;
|
||||
const s = S.queue[S.qIdx];
|
||||
const { getLyricsBySongId } = await import('./api.js');
|
||||
if(token !== _lyricsLoadToken) return;
|
||||
|
||||
// 1. Try Navidrome structured lyrics
|
||||
const lyrics = await getLyricsBySongId(songId);
|
||||
if(token !== _lyricsLoadToken) return;
|
||||
const track = lyrics[0];
|
||||
if(track?.synced && track.line?.length) {
|
||||
|
||||
content.innerHTML = '';
|
||||
if(track?.synced && track.line?.length) {
|
||||
_renderSyncedLines(content, track.line.map(l => ({ start: l.start, value: l.value || '' })).filter(l => l.value));
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Fallback: fetch lyrics from LRCLIB
|
||||
// Use only first artist (multi-artist strings like "A / B" break lookup)
|
||||
const firstArtist = (s?.artist||'').split(/[/,]/)[0].trim();
|
||||
let lrcText = null;
|
||||
let lrclibPlain = null;
|
||||
try {
|
||||
// Try with album first, then without (album mismatch causes 404)
|
||||
const attempts = [
|
||||
new URLSearchParams({ artist_name: firstArtist, track_name: s?.title||'', ...(s?.album ? { album_name: s.album } : {}) }),
|
||||
...(s?.album ? [new URLSearchParams({ artist_name: firstArtist, track_name: s?.title||'' })] : []),
|
||||
];
|
||||
for(const p of attempts) {
|
||||
if(token !== _lyricsLoadToken) return;
|
||||
const r = await fetch(`https://lrclib.net/api/get?${p}`, { signal: AbortSignal.timeout(6000) });
|
||||
if(r.ok) {
|
||||
const d = await r.json();
|
||||
lrcText = d.syncedLyrics || null;
|
||||
lrclibPlain = d.plainLyrics || null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
if(token !== _lyricsLoadToken) return;
|
||||
|
||||
content.innerHTML = '';
|
||||
if(lrcText) {
|
||||
const parsed = _parseLrc(lrcText);
|
||||
if(parsed.length) { _renderSyncedLines(content, parsed); return; }
|
||||
}
|
||||
|
||||
// 3. Plain text — prefer LRCLIB plain over Navidrome plain (usually better quality)
|
||||
const plain = lrclibPlain
|
||||
|| (track?.line?.length ? track.line.map(l => l.value).join('\n') : null);
|
||||
const plain = track?.line?.length ? track.line.map(l => l.value).join('\n') : null;
|
||||
if(plain) {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'lyrics-plain';
|
||||
|
||||
Reference in new issue
Block a user