fix ms and support .m, .mm, .mmm

This commit is contained in:
Kendall Garner
2023-12-13 20:35:47 -08:00
parent 235010ce73
commit b0b38cfa0d
2 changed files with 21 additions and 5 deletions

View File

@@ -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
}
}

View File

@@ -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"},
}))
})
})