mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-09 02:47:29 +02:00
fix ms and support .m, .mm, .mmm
This commit is contained in:
parent
235010ce73
commit
b0b38cfa0d
2 changed files with 21 additions and 5 deletions
|
|
@ -139,17 +139,21 @@ func ToLyrics(language, text string) (*Lyric, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
secStart := match[8]
|
||||
if secStart != -1 {
|
||||
secEnd := match[9]
|
||||
msStart := match[8]
|
||||
if msStart != -1 {
|
||||
msEnd := match[9]
|
||||
// +1 offset since this capture group contains .
|
||||
millis, err = strconv.ParseInt(line[secStart+1:secEnd], 10, 64)
|
||||
millis, err = strconv.ParseInt(line[msStart+1:msEnd], 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if secEnd-secStart == 3 {
|
||||
len := msEnd - msStart
|
||||
|
||||
if len == 3 {
|
||||
millis *= 10
|
||||
} else if len == 2 {
|
||||
millis *= 100
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,4 +89,16 @@ var _ = Describe("ToLyrics", func() {
|
|||
{Start: &a, Value: "Text"},
|
||||
}))
|
||||
})
|
||||
|
||||
It("Handles all possible ms cases", func() {
|
||||
a, b, c := int64(1), int64(10), int64(100)
|
||||
lyrics, err := ToLyrics("xxx", "[00:00.001]a\n[00:00.01]b\n[00:00.1]c")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lyrics.Synced).To(BeTrue())
|
||||
Expect(lyrics.Line).To(Equal([]Line{
|
||||
{Start: &a, Value: "a"},
|
||||
{Start: &b, Value: "b"},
|
||||
{Start: &c, Value: "c"},
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue