diff --git a/model/lyrics.go b/model/lyrics.go index 213a808a5..356e09624 100644 --- a/model/lyrics.go +++ b/model/lyrics.go @@ -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 } } diff --git a/model/lyrics_test.go b/model/lyrics_test.go index 0dd879feb..6dedeea2b 100644 --- a/model/lyrics_test.go +++ b/model/lyrics_test.go @@ -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"}, + })) + }) })