Implement songLyrics extension: getLyricsBySongId with real word/syllable cues
Adds getLyricsBySongId (versions 1 and 2 of the songLyrics extension, gated by the enhanced param): returns every stored structuredLyrics entry for a song, including line-level start times for synced lyrics and, only when a source actually provided word/syllable timing (an Enhanced LRC sidecar) and enhanced=true was requested, cueLine/cue data with the precomputed UTF-8 byte offsets. Plain and non-enhanced synced lyrics never get fabricated cue data. Removes the now-dead SetSongLyrics writer (superseded by database.InsertLyrics); SongLyricsPlainText keeps serving the legacy getLyrics endpoint unchanged. Adds a scanner integration test proving a sidecar .lrc (with an Enhanced LRC line) is discovered and indexed during a real scan. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014r98AtcBbevpscWLsfwVvv
This commit is contained in:
@@ -237,3 +237,45 @@ func TestScanFolderRejectsConcurrentScan(t *testing.T) {
|
||||
t.Fatal("expected error scanning a folder that is already being scanned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanFolderIndexesSidecarLRC(t *testing.T) {
|
||||
s, folder, dir := newTestScanner(t)
|
||||
genFile(t, dir, "song1.mp3", "Song One", "Artist One")
|
||||
|
||||
lrc := "[ar:Artist One]\n[00:01.00]Hello world\n[00:02.50]<00:02.50>Second <00:02.90>line\n"
|
||||
if err := os.WriteFile(filepath.Join(dir, "song1.lrc"), []byte(lrc), 0o644); err != nil {
|
||||
t.Fatalf("write sidecar lrc: %v", err)
|
||||
}
|
||||
|
||||
if err := s.ScanFolder(context.Background(), folder.ID); err != nil {
|
||||
t.Fatalf("ScanFolder: %v", err)
|
||||
}
|
||||
|
||||
songs, err := database.ListSongs(s.DB, 10, 0)
|
||||
if err != nil || len(songs) != 1 {
|
||||
t.Fatalf("ListSongs: %v %v", songs, err)
|
||||
}
|
||||
|
||||
entries, err := database.GetSongStructuredLyrics(s.DB, songs[0].ID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetSongStructuredLyrics: %v", err)
|
||||
}
|
||||
var synced *database.StructuredLyricsRow
|
||||
for i := range entries {
|
||||
if entries[i].Synced {
|
||||
synced = &entries[i]
|
||||
}
|
||||
}
|
||||
if synced == nil {
|
||||
t.Fatalf("expected a synced structuredLyrics entry from the sidecar .lrc, got %+v", entries)
|
||||
}
|
||||
if len(synced.Lines) != 2 || synced.Lines[0].Text != "Hello world" {
|
||||
t.Fatalf("lines = %+v", synced.Lines)
|
||||
}
|
||||
if synced.Lines[0].StartMs == nil || *synced.Lines[0].StartMs != 1000 {
|
||||
t.Errorf("line[0].StartMs = %v, want 1000", synced.Lines[0].StartMs)
|
||||
}
|
||||
if len(synced.Lines[1].Words) != 2 {
|
||||
t.Fatalf("expected word-level cues from Enhanced LRC line, got %+v", synced.Lines[1])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user