fix ttml match
This commit is contained in:
parent
bafb3ee310
commit
337d04b813
@ -1252,15 +1252,20 @@ func conventTTMLToLRC(ttml string) (string, error) {
|
|||||||
var lrcLines []string
|
var lrcLines []string
|
||||||
for _, item := range parsedTTML.FindElement("tt").FindElement("body").ChildElements() {
|
for _, item := range parsedTTML.FindElement("tt").FindElement("body").ChildElements() {
|
||||||
for _, lyric := range item.ChildElements() {
|
for _, lyric := range item.ChildElements() {
|
||||||
var m, s, ms int
|
var h, m, s, ms int
|
||||||
if lyric.SelectAttr("begin") == nil {
|
if lyric.SelectAttr("begin") == nil {
|
||||||
return "", errors.New("no synchronised lyrics")
|
return "", errors.New("no synchronised lyrics")
|
||||||
}
|
}
|
||||||
if strings.Contains(lyric.SelectAttr("begin").Value, ":") {
|
if strings.Contains(lyric.SelectAttr("begin").Value, ":") {
|
||||||
_, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d.%d", &m, &s, &ms)
|
_, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d:%d.%d", &h, &m, &s, &ms)
|
||||||
} else {
|
if err != nil {
|
||||||
_, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d.%d", &s, &ms)
|
_, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d:%d.%d", &m, &s, &ms)
|
||||||
m = 0
|
h = 0
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
_, err = fmt.Sscanf(lyric.SelectAttr("begin").Value, "%d.%d", &s, &ms)
|
||||||
|
h, m = 0, 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -1279,6 +1284,7 @@ func conventTTMLToLRC(ttml string) (string, error) {
|
|||||||
} else {
|
} else {
|
||||||
text = lyric.SelectAttr("text").Value
|
text = lyric.SelectAttr("text").Value
|
||||||
}
|
}
|
||||||
|
m += h * 60
|
||||||
lrcLines = append(lrcLines, fmt.Sprintf("[%02d:%02d.%03d]%s", m, s, ms, text))
|
lrcLines = append(lrcLines, fmt.Sprintf("[%02d:%02d.%03d]%s", m, s, ms, text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user