mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-12 12:27:09 +02:00
refactor(lyrics): fold parseLyricsfile into lyricParser signature and rename file
- parseLyricsfile now matches the lyricParser signature directly (reads via
bytes.NewReader), removing the parseLyricsfileBytes adapter and the
string(contents) copy; the lyricFormats table references it directly.
- StructuredLyrics drops the vestigial LyricList{} init (json.Unmarshal
overwrites; MarshalJSON owns the empty->[] invariant).
- Rename lyricsfile.go -> lyrics_lyricsfile.go (and its test) to match the
lyrics_<format>.go convention used by lrc/srt/ttml.
This commit is contained in:
parent
4faed5bc44
commit
fd700f8d8a
4 changed files with 14 additions and 17 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
|
|
@ -19,9 +20,9 @@ import (
|
|||
// overlapping lines are attributed to synthetic voice agents via lowest-free
|
||||
// voice ID assignment so the OpenSubsonic v2 enhanced response can split
|
||||
// parallel vocals.
|
||||
func parseLyricsfile(text string) (LyricList, error) {
|
||||
func parseLyricsfile(_ string, contents []byte) (LyricList, error) {
|
||||
var doc lyricsfileDocument
|
||||
dec := yaml.NewDecoder(strings.NewReader(text))
|
||||
dec := yaml.NewDecoder(bytes.NewReader(contents))
|
||||
dec.KnownFields(false)
|
||||
if err := dec.Decode(&doc); err != nil {
|
||||
return nil, fmt.Errorf("not a valid Lyricsfile YAML: %w", err)
|
||||
|
|
@ -8,7 +8,7 @@ import (
|
|||
var _ = Describe("parseLyricsfile", func() {
|
||||
DescribeTable("returns nil,nil for YAML without the Lyricsfile version marker",
|
||||
func(input string) {
|
||||
lyrics, err := parseLyricsfile(input)
|
||||
lyrics, err := parseLyricsfile("", []byte(input))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics).To(BeNil())
|
||||
},
|
||||
|
|
@ -22,7 +22,7 @@ lines:
|
|||
)
|
||||
|
||||
It("returns an error for invalid YAML", func() {
|
||||
_, err := parseLyricsfile("not: valid: yaml: [")
|
||||
_, err := parseLyricsfile("", []byte("not: valid: yaml: ["))
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ lines:
|
|||
- text: "You know the rules and so do I"
|
||||
start_ms: 22801
|
||||
`
|
||||
lyrics, err := parseLyricsfile(input)
|
||||
lyrics, err := parseLyricsfile("", []byte(input))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics).To(HaveLen(1))
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ plain: |
|
|||
|
||||
Second line
|
||||
`
|
||||
lyrics, err := parseLyricsfile(input)
|
||||
lyrics, err := parseLyricsfile("", []byte(input))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics).To(HaveLen(1))
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ lines:
|
|||
start_ms: 1500
|
||||
end_ms: 3000
|
||||
`
|
||||
lyrics, err := parseLyricsfile(input)
|
||||
lyrics, err := parseLyricsfile("", []byte(input))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics).To(HaveLen(1))
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ lines:
|
|||
start_ms: 3000
|
||||
end_ms: 3500
|
||||
`
|
||||
lyrics, err := parseLyricsfile(input)
|
||||
lyrics, err := parseLyricsfile("", []byte(input))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics).To(HaveLen(1))
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ lines:
|
|||
start_ms: 2000
|
||||
end_ms: 3000
|
||||
`
|
||||
lyrics, err := parseLyricsfile(input)
|
||||
lyrics, err := parseLyricsfile("", []byte(input))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics).To(HaveLen(1))
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ metadata:
|
|||
language: 'eng'
|
||||
instrumental: true
|
||||
`
|
||||
lyrics, err := parseLyricsfile(input)
|
||||
lyrics, err := parseLyricsfile("", []byte(input))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics).To(HaveLen(1))
|
||||
|
||||
|
|
@ -269,7 +269,7 @@ lines:
|
|||
start_ms: 2000
|
||||
end_ms: 3000
|
||||
`
|
||||
lyrics, err := parseLyricsfile(input)
|
||||
lyrics, err := parseLyricsfile("", []byte(input))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics).To(HaveLen(1))
|
||||
|
||||
|
|
@ -14,10 +14,6 @@ import (
|
|||
// do not carry their own.
|
||||
type lyricParser func(lang string, contents []byte) (LyricList, error)
|
||||
|
||||
func parseLyricsfileBytes(_ string, contents []byte) (LyricList, error) {
|
||||
return parseLyricsfile(string(contents))
|
||||
}
|
||||
|
||||
// lyricFormats is the structured formats in content-sniff probe order; each
|
||||
// row's suffixes drive sidecar dispatch. LRC/plain is the unlisted fallback floor.
|
||||
var lyricFormats = []struct {
|
||||
|
|
@ -26,7 +22,7 @@ var lyricFormats = []struct {
|
|||
}{
|
||||
{[]string{".ttml"}, parseTTMLWithDefaultLang},
|
||||
{[]string{".srt"}, parseSRTWithLanguage},
|
||||
{[]string{".yaml", ".yml"}, parseLyricsfileBytes},
|
||||
{[]string{".yaml", ".yml"}, parseLyricsfile},
|
||||
}
|
||||
|
||||
// ParseLyrics is the single entry point for parsing lyrics. A known suffix routes
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ func (mf MediaFile) AlbumCoverArtID() ArtworkID {
|
|||
}
|
||||
|
||||
func (mf MediaFile) StructuredLyrics() (LyricList, error) {
|
||||
lyrics := LyricList{}
|
||||
var lyrics LyricList
|
||||
err := json.Unmarshal([]byte(mf.Lyrics), &lyrics)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue