handle errors of lyric embed

This commit is contained in:
tramhao 2021-03-02 23:49:27 +08:00
parent be2d4f5ef3
commit e4deba451e
2 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package lyric
import (
"fmt"
"html"
"net/url"
"regexp"
@ -29,8 +30,13 @@ func GetLyric(url string) (string, error) {
if err != nil {
return "", err
}
return lyric, nil
if lyric == "" {
return "", fmt.Errorf("no lyric available")
}
if looksLikeLRC(lyric) {
return lyric, nil
}
return "", fmt.Errorf("lyric not compatible")
}
// GetLyricOptions queries available song lyrics. It returns map of title and

View File

@ -98,5 +98,8 @@ func GetLyricChinese(lyricID string, serviceProvider string) (string, error) {
// io.WriteString(file, lyric)
// file.Close()
// }
return lyric, nil
if looksLikeLRC(lyric) {
return lyric, nil
}
return "", fmt.Errorf("lyric not compatible")
}