Fix comment format

This commit is contained in:
tramhao 2021-02-28 23:19:42 +08:00
parent 83872c9b3d
commit 146daafa37
3 changed files with 22 additions and 4 deletions

View File

@ -439,14 +439,16 @@ func (c Command) defineCommands() {
c.define("lyric_delay_increase", func() {
err := gomu.playingBar.delayLyric(500)
if err != nil {
logError(err)
errorPopup(err)
gomu.app.Draw()
}
})
c.define("lyric_delay_decrease", func() {
err := gomu.playingBar.delayLyric(-500)
if err != nil {
logError(err)
errorPopup(err)
gomu.app.Draw()
}
})

View File

@ -1,5 +1,5 @@
//Package lyric package download lyrics from different website and embed them into mp3 file.
//lrc file is used to parse lrc file into subtitle. Similar to subtitles package
// Package lyric package download lyrics from different website and embed them into mp3 file.
// lrc file is used to parse lrc file into subtitle. Similar to subtitles package
package lyric
import (
@ -35,6 +35,7 @@ func looksLikeLRC(s string) bool {
func NewFromLRC(s string) (res subtitles.Subtitle, err error) {
endString := "[158:00.00]The End" + eol
s = s + endString
s = cleanLRC(s)
r1 := regexp.MustCompile(`(?U)^\[[0-9].*\]`)
lines := strings.Split(s, "\n")
outSeq := 1
@ -121,3 +122,14 @@ func parseLrcTime(in string) (time.Time, error) {
func makeTime(h int, m int, s int, ms int) time.Time {
return time.Date(0, 1, 1, h, m, s, ms*1000*1000, time.UTC)
}
// cleanLRC clean the string download
func cleanLRC(s string) (cleanLyric string) {
// Clean ' to '
s = strings.Replace(s, "'", "'", -1)
// It's wierd that sometimes there are two ajacent ''.
// Replace it anyway
cleanLyric = strings.Replace(s, "''", "'", -1)
return cleanLyric
}

View File

@ -69,6 +69,10 @@ func GetLyricChinese(lyricID string, serviceProvider string) (string, error) {
return "", err
}
lyric = dataMap["lyric"].(string)
if lyric == "" {
err = fmt.Errorf("no lyric available")
return "", err
}
if looksLikeLRC(lyric) {
var tmpSubtitle subtitles.Subtitle
tmpSubtitle, err = NewFromLRC(lyric)