Skip to content

Commit 688aa1c

Browse files
committed
Merge branch 'dev'
# Conflicts: # .github/workflows/build.yml # .github/workflows/docker.yml
2 parents 2eb5fd5 + 90d9464 commit 688aa1c

File tree

8 files changed

+63
-26
lines changed

8 files changed

+63
-26
lines changed

build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 CC=clang go build -o bin/lrcAPI_v$1_darwin_arm64
4+
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 CC="clang -arch x86_64" go build -o bin/lrcAPI_v$1_darwin_amd64
5+
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-musl-gcc go build -o bin/lrcAPI_v$1_linux_amd64
6+
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-musl-gcc go build -o bin/lrcAPI_v$1_linux_arm64
7+
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -o bin/lrcAPI_v$1_windows_amd64.exe
8+
GOOS=windows GOARCH=arm64 CGO_ENABLED=1 CC=/opt/llvm-mingw/bin/aarch64-w64-mingw32-gcc go build -o bin/lrcAPI_v$1_windows_arm64.exe
9+
10+

command/command.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package command
22

3+
import (
4+
"github.com/common-nighthawk/go-figure"
5+
"os"
6+
)
7+
38
func Arg(args []string) {
9+
figlet := figure.NewFigure("LrcAPI-Go", "", true)
10+
figlet.Print()
411
for index, arg := range args {
512
if index == 0 {
613
continue
@@ -12,4 +19,8 @@ func Arg(args []string) {
1219
Pwd = args[index+1]
1320
}
1421
}
22+
dir, _ := os.Getwd()
23+
if os.Getenv("PWD") != "" && os.Getenv("PWD") != dir {
24+
Pwd = os.Getenv("PWD")
25+
}
1526
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/bytedance/sonic/loader v0.2.4 // indirect
88
github.com/cloudwego/base64x v0.1.5 // indirect
99
github.com/cloudwego/iasm v0.2.0 // indirect
10+
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
1011
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
1112
github.com/gin-contrib/cors v1.7.5 // indirect
1213
github.com/gin-contrib/sse v1.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCy
77
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
88
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
99
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
10+
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
11+
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
1012
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1113
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1214
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=

handler/lyric.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"lrcAPI/request"
88
"lrcAPI/util"
99
"net/http"
10+
"strconv"
1011
)
1112

1213
func lyricHandler(c *gin.Context) {
@@ -35,9 +36,9 @@ func lyricHandler(c *gin.Context) {
3536
util.ErrorPrinter(err)
3637
c.JSON(404, gin.H{})
3738
}
38-
for _, value := range lyricRequest.Processor.InfoLyric {
39+
for index, value := range lyricRequest.Processor.InfoLyric {
3940
lyricRequest.File.InfoLyric = append(lyricRequest.File.InfoLyric, file.InfoLyric{
40-
ID: value.ID,
41+
ID: strconv.Itoa(index),
4142
Title: value.Title,
4243
Artist: value.Artist,
4344
Lyric: value.Lyric,

processor/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package processor
22

3+
var (
4+
API_TOT = 2
5+
NETEASE_API_COUNT = 0
6+
QQ_API_COUNT = 1
7+
)
8+
39
type Processor struct {
410
InfoLyric []InfoLyric
511
Title string `json:"title"`
612
Artist string `json:"artist"`
713
}
814

915
type InfoLyric struct {
10-
ID string `json:"id"`
16+
Index int `json:"index"`
1117
Title string `json:"title"`
1218
Artist string `json:"artist"`
1319
Lyric string `json:"lyrics"`
20+
API string `json:"api"`
1421
}

processor/lyric.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
package processor
22

33
import (
4+
"fmt"
45
"github.com/pkg/errors"
56
"lrcAPI/util"
6-
"strconv"
7+
"sort"
78
)
89

910
func (data *Processor) Process() error {
10-
var titles, artists, oriLrc, trLrc []string
11-
if err := netease(data, &titles, &artists, &oriLrc, &trLrc); err != nil {
11+
if err := netease(data); err != nil {
1212
return errors.Wrap(err, "neteaseAPI")
1313
}
14-
if err := qq(data, &titles, &artists, &oriLrc, &trLrc); err != nil {
14+
if err := qq(data); err != nil {
1515
return errors.Wrap(err, "qqAPI")
1616
}
17-
for index, _ := range titles {
18-
infoLyric := InfoLyric{
19-
ID: strconv.Itoa(index),
20-
Title: titles[index],
21-
Artist: artists[index],
22-
Lyric: util.LrcTranslationBlender(oriLrc[index], trLrc[index]),
23-
}
24-
data.InfoLyric = append(data.InfoLyric, infoLyric)
25-
}
17+
sort.Slice(data.InfoLyric, func(i, j int) bool {
18+
return data.InfoLyric[i].Index < data.InfoLyric[j].Index
19+
})
20+
data.InfoLyric = append(data.InfoLyric, InfoLyric{
21+
Index: -1,
22+
Title: data.Title,
23+
Artist: data.Artist,
24+
Lyric: fmt.Sprintf("[00:00.00]%s\n[00:00.00]%s", data.Title, data.Artist),
25+
})
2626
return nil
2727
}
2828

29-
func netease(data *Processor, Titles, Artists, OriLrc, TrLrc *[]string) error {
29+
func netease(data *Processor) error {
3030
musicIDs, titles, artists, err := util.NeteaseGetMusic(data.Title, data.Artist)
3131
if err != nil {
3232
return errors.WithStack(err)
@@ -39,15 +39,17 @@ func netease(data *Processor, Titles, Artists, OriLrc, TrLrc *[]string) error {
3939
if err != nil {
4040
return errors.WithStack(err)
4141
}
42-
*Titles = append(*Titles, (*titles)[index])
43-
*Artists = append(*Artists, (*artists)[index])
44-
*OriLrc = append(*OriLrc, oriLrc)
45-
*TrLrc = append(*TrLrc, trLrc)
42+
data.InfoLyric = append(data.InfoLyric, InfoLyric{
43+
Index: API_TOT*index + NETEASE_API_COUNT,
44+
Title: (*titles)[index] + " (网易云音乐)",
45+
Artist: (*artists)[index],
46+
Lyric: util.LrcTranslationBlender(oriLrc, trLrc),
47+
})
4648
}
4749
return nil
4850
}
4951

50-
func qq(data *Processor, Titles, Artists, OriLrc, TrLrc *[]string) error {
52+
func qq(data *Processor) error {
5153
musicIDs, musicMIDs, titles, artists, err := util.QQGetMusic(data.Title)
5254
if err != nil {
5355
return errors.WithStack(err)
@@ -60,10 +62,12 @@ func qq(data *Processor, Titles, Artists, OriLrc, TrLrc *[]string) error {
6062
if err != nil {
6163
return errors.WithStack(err)
6264
}
63-
*Titles = append(*Titles, (*titles)[index])
64-
*Artists = append(*Artists, (*artists)[index])
65-
*OriLrc = append(*OriLrc, oriLrc)
66-
*TrLrc = append(*TrLrc, trLrc)
65+
data.InfoLyric = append(data.InfoLyric, InfoLyric{
66+
Index: API_TOT*index + QQ_API_COUNT,
67+
Title: (*titles)[index] + " (QQ音乐)",
68+
Artist: (*artists)[index],
69+
Lyric: util.LrcTranslationBlender(oriLrc, trLrc),
70+
})
6771
}
6872
return nil
6973
}

util/netease.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type neteaseSerachIDResponse struct {
4040
// 通过ID查找歌词
4141
// 返回歌词,翻译歌词以及错误
4242
// 返回的歌词都是未转译的
43+
// 若返回的歌词数据是空的,那就是无歌词(纯音乐)
4344
func NeteaseGetLyric(ID string) (string, string, error) {
4445
url := fmt.Sprintf(neteaseLrcURLTemplate, ID)
4546
req, _ := http.NewRequest("GET", url, nil)

0 commit comments

Comments
 (0)