重构项目,调整了项目结构

This commit is contained in:
Hami Lemon 2022-03-28 18:26:40 +08:00
parent 5f49bde3ae
commit c9b1b38c03
11 changed files with 456 additions and 386 deletions

View file

@ -1,4 +1,4 @@
package main
package lrc2srt
import (
"compress/gzip"
@ -6,7 +6,6 @@ import (
"fmt"
"net/http"
"net/url"
"os"
)
/**
@ -43,17 +42,17 @@ func GetQQLyric(id string) (lyric, tLyric string) {
req, _ := http.NewRequest("GET", api, nil)
//必须设置Referer,否则会请求失败
req.Header.Add("Referer", "https://y.qq.com")
req.Header.Add("User-Agent", ChromeUA)
req.Header.Add("User-Agent", CHROME_UA)
req.Header.Add("accept-encoding", "gzip")
resp, err := client.Do(req)
if err != nil {
fmt.Printf("网络错误:%v\n", err)
os.Exit(1)
panic("网络异常,请求失败。")
}
if resp == nil || resp.StatusCode != http.StatusOK {
fmt.Printf("网络请求失败,状态码为:%d\n", resp.StatusCode)
os.Exit(1)
panic("获取失败,未能正确获取到数据")
}
defer resp.Body.Close()
@ -63,7 +62,7 @@ func GetQQLyric(id string) (lyric, tLyric string) {
err = json.NewDecoder(reader).Decode(&qqLyric)
if qqLyric.RetCode != 0 {
fmt.Printf("获取歌词失败,返回的结果为:%+v请检查id是否正确\n", qqLyric)
os.Exit(1)
panic("id错误获取歌词失败。")
}
return qqLyric.Lyric, qqLyric.Trans
}