fix ttml match

pull/8/head
itouakirai 7 months ago committed by GitHub
parent f0a3d487d7
commit bafb3ee310
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      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))
}
}

Loading…
Cancel
Save