mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-20 09:08:50 +01:00
Replace model.ToLyrics (LRC/plain only) with model.ParseEmbedded so plugin responses are content-sniffed for TTML, SRT, YAML, LRC, and plain text. ParseEmbedded returns a LyricList, so the loop now flattens multiple tracks per response entry. The test-lyrics WASM plugin gains a "ttml" format mode (configured via pdk.GetConfig) that returns a minimal TTML document; rebuilt with the standard Go wasip1 toolchain (GOOS=wasip1 GOARCH=wasm). A new Ginkgo test asserts Synced==true and the exact cue value, which the old plain-text path could not produce. GetLyrics doc comment updated to reflect content-sniffing; a later task will retarget it to ParseLyrics once that function is introduced.
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
// Test lyrics plugin for Navidrome plugin system integration tests.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/navidrome/navidrome/plugins/pdk/go/lyrics"
|
|
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
|
|
)
|
|
|
|
func init() {
|
|
lyrics.Register(&testLyrics{})
|
|
}
|
|
|
|
type testLyrics struct{}
|
|
|
|
func (t *testLyrics) GetLyrics(input lyrics.GetLyricsRequest) (lyrics.GetLyricsResponse, error) {
|
|
// Check for configured error
|
|
errMsg, hasErr := pdk.GetConfig("error")
|
|
if hasErr && errMsg != "" {
|
|
return lyrics.GetLyricsResponse{}, fmt.Errorf("%s", errMsg)
|
|
}
|
|
|
|
// Return a minimal TTML document to exercise content-sniffing for rich formats.
|
|
format, hasFormat := pdk.GetConfig("format")
|
|
if hasFormat && format == "ttml" {
|
|
const ttml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<tt xmlns="http://www.w3.org/ns/ttml">
|
|
<body xml:lang="eng">
|
|
<div>
|
|
<p begin="00:00.000" end="00:01.000">plugin ttml line</p>
|
|
</div>
|
|
</body>
|
|
</tt>`
|
|
return lyrics.GetLyricsResponse{
|
|
Lyrics: []lyrics.LyricsText{
|
|
{Lang: "eng", Text: ttml},
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
// Check if we should omit language (to test default language handling)
|
|
noLang, hasNoLang := pdk.GetConfig("no_lang")
|
|
lang := "eng"
|
|
if hasNoLang && noLang == "true" {
|
|
lang = ""
|
|
}
|
|
|
|
// Return test lyrics based on track info
|
|
return lyrics.GetLyricsResponse{
|
|
Lyrics: []lyrics.LyricsText{
|
|
{
|
|
Lang: lang,
|
|
Text: "Test lyrics for " + input.Track.Title + "\nBy " + input.Track.Artist,
|
|
},
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func main() {}
|