From f0a3d487d7ea4ba1abeafb0b4e4a43421d9511df Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Thu, 25 Apr 2024 01:47:29 +0800 Subject: [PATCH 1/3] fix ttml match --- main.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 16d7236..a93aa39 100644 --- a/main.go +++ b/main.go @@ -1218,15 +1218,20 @@ func conventTTMLToLRC(ttml string) (string, error) { var lrcLines []string for _, item := range parsedTTML.FindElement("tt").FindElement("body").ChildElements() { for _, lyric := range item.ChildElements() { - var m, s, ms int + var h, m, s, ms int if lyric.SelectAttr("begin") == nil { return "", errors.New("no synchronised lyrics") } if strings.Contains(lyric.SelectAttr("begin").Value, ":") { - _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d.%d", &m, &s, &ms) - } else { - _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d.%d", &s, &ms) - m = 0 + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d:%d.%d", &h, &m, &s, &ms) + if err != nil { + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d.%d", &m, &s, &ms) + h = 0 + } + if err != nil { + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d.%d", &s, &ms) + h, m = 0, 0 + } } if err != nil { return "", err @@ -1245,6 +1250,7 @@ func conventTTMLToLRC(ttml string) (string, error) { } else { text = lyric.SelectAttr("text").Value } + m += h * 60 lrcLines = append(lrcLines, fmt.Sprintf("[%02d:%02d.%03d]%s", m, s, ms, text)) } } From bafb3ee310faa4aa4a44bd58dfcf413efcf740ed Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Thu, 25 Apr 2024 01:49:01 +0800 Subject: [PATCH 2/3] fix ttml match --- main_atmos.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main_atmos.go b/main_atmos.go index 1573cac..02c9ffb 100644 --- a/main_atmos.go +++ b/main_atmos.go @@ -1252,15 +1252,20 @@ func conventTTMLToLRC(ttml string) (string, error) { var lrcLines []string for _, item := range parsedTTML.FindElement("tt").FindElement("body").ChildElements() { for _, lyric := range item.ChildElements() { - var m, s, ms int + var h, m, s, ms int if lyric.SelectAttr("begin") == nil { return "", errors.New("no synchronised lyrics") } if strings.Contains(lyric.SelectAttr("begin").Value, ":") { - _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d.%d", &m, &s, &ms) - } else { - _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d.%d", &s, &ms) - m = 0 + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d:%d.%d", &h, &m, &s, &ms) + if err != nil { + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d.%d", &m, &s, &ms) + h = 0 + } + if err != nil { + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d.%d", &s, &ms) + h, m = 0, 0 + } } if err != nil { return "", err @@ -1279,6 +1284,7 @@ func conventTTMLToLRC(ttml string) (string, error) { } else { text = lyric.SelectAttr("text").Value } + m += h * 60 lrcLines = append(lrcLines, fmt.Sprintf("[%02d:%02d.%03d]%s", m, s, ms, text)) } } From 337d04b8131023a2d22f3a7a05861f98f84ed610 Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Thu, 25 Apr 2024 01:50:16 +0800 Subject: [PATCH 3/3] fix ttml match --- main_select.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main_select.go b/main_select.go index 4a0074c..24f0e06 100644 --- a/main_select.go +++ b/main_select.go @@ -1252,15 +1252,20 @@ func conventTTMLToLRC(ttml string) (string, error) { var lrcLines []string for _, item := range parsedTTML.FindElement("tt").FindElement("body").ChildElements() { for _, lyric := range item.ChildElements() { - var m, s, ms int + var h, m, s, ms int if lyric.SelectAttr("begin") == nil { return "", errors.New("no synchronised lyrics") } if strings.Contains(lyric.SelectAttr("begin").Value, ":") { - _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d.%d", &m, &s, &ms) - } else { - _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d.%d", &s, &ms) - m = 0 + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d:%d.%d", &h, &m, &s, &ms) + if err != nil { + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d.%d", &m, &s, &ms) + h = 0 + } + if err != nil { + _, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d.%d", &s, &ms) + h, m = 0, 0 + } } if err != nil { return "", err @@ -1279,6 +1284,7 @@ func conventTTMLToLRC(ttml string) (string, error) { } else { text = lyric.SelectAttr("text").Value } + m += h * 60 lrcLines = append(lrcLines, fmt.Sprintf("[%02d:%02d.%03d]%s", m, s, ms, text)) } }