diff --git a/command.go b/command.go index 4d7aabb..73e070b 100644 --- a/command.go +++ b/command.go @@ -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() } }) diff --git a/lyric/lrc.go b/lyric/lrc.go index 7d08420..1c0db74 100644 --- a/lyric/lrc.go +++ b/lyric/lrc.go @@ -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 +} diff --git a/lyric/lyric_chinese.go b/lyric/lyric_chinese.go index eb65f15..26d21a9 100644 --- a/lyric/lyric_chinese.go +++ b/lyric/lyric_chinese.go @@ -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)