Skip to content

Commit 953551d

Browse files
committed
v1.0
2 parents 4bcbade + 588771b commit 953551d

File tree

19 files changed

+541
-0
lines changed

19 files changed

+541
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.idea
22
/assets
3+
/bin
4+
lrcAPI

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# lrcAPI - Go
2+
为Stream Music音流写的一个基于Go的歌词获取工具。特点
3+
+ 有缓存机制
4+
+ Go编写,速度嘎嘎快
5+
6+
# 启动参数
7+
+ `--port xxxx` - 设定端口为xxxx
8+
+ `--pwd xxxxxxx` - 设定验证密码为xxxxxxx
9+
10+
注意,Linux需要安装`musl`运行环境,请自行谷歌
11+
12+
# 使用参数,参照截图
13+
![](https://raw.githubusercontent.com/stephen-zeng/img/master/20250409232913.png)

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package command
2+
3+
func Arg(args []string) {
4+
for index, arg := range args {
5+
if index == 0 {
6+
continue
7+
}
8+
switch arg {
9+
case "--port":
10+
Port = args[index+1]
11+
case "--pwd":
12+
Pwd = args[index+1]
13+
}
14+
}
15+
}

command/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package command
2+
3+
var (
4+
Pwd string = "123456"
5+
Port string = "1111"
6+
)

file/config.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package file
2+
3+
import "os"
4+
5+
// 文件包负责读写
6+
type File struct {
7+
HasPrevious bool
8+
FolderName string
9+
InfoLyric []InfoLyric
10+
}
11+
12+
type InfoLyric struct {
13+
ID string `json:"id"`
14+
Title string `json:"title"`
15+
Artist string `json:"artist"`
16+
Lyric string `json:"lyrics"`
17+
}
18+
19+
func init() {
20+
os.Mkdir("assets", 0777)
21+
}

file/lyric.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package file
2+
3+
import (
4+
"encoding/json"
5+
"github.com/pkg/errors"
6+
"os"
7+
"sort"
8+
)
9+
10+
func (info *File) WriteLyric() error {
11+
pathName := "assets/" + info.FolderName
12+
os.Mkdir(pathName, 0777)
13+
for _, infoLyric := range info.InfoLyric {
14+
lyricFile, err := os.Create(pathName + "/" + infoLyric.ID + ".json")
15+
if err != nil {
16+
return errors.WithStack(err)
17+
}
18+
defer lyricFile.Close()
19+
encoder := json.NewEncoder(lyricFile)
20+
encoder.Encode(infoLyric)
21+
}
22+
return nil
23+
}
24+
25+
func (info *File) ReadLyric() error {
26+
pathName := "assets/" + info.FolderName
27+
lyricFolder, err := os.ReadDir(pathName)
28+
if err != nil {
29+
return errors.WithStack(err)
30+
}
31+
info.HasPrevious = true
32+
sort.Slice(lyricFolder, func(i, j int) bool {
33+
return lyricFolder[i].Name() < lyricFolder[j].Name()
34+
})
35+
for _, infoLyricFile := range lyricFolder {
36+
lyricFile, _ := os.Open(pathName + "/" + infoLyricFile.Name())
37+
defer lyricFile.Close()
38+
decoder := json.NewDecoder(lyricFile)
39+
var infoLyric InfoLyric
40+
decoder.Decode(&infoLyric)
41+
info.InfoLyric = append(info.InfoLyric, infoLyric)
42+
}
43+
return nil
44+
}

go.mod

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
module lrcAPI
22

33
go 1.24.2
4+
5+
require (
6+
github.com/bytedance/sonic v1.13.2 // indirect
7+
github.com/bytedance/sonic/loader v0.2.4 // indirect
8+
github.com/cloudwego/base64x v0.1.5 // indirect
9+
github.com/cloudwego/iasm v0.2.0 // indirect
10+
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
11+
github.com/gin-contrib/cors v1.7.5 // indirect
12+
github.com/gin-contrib/sse v1.1.0 // indirect
13+
github.com/gin-gonic/gin v1.10.0 // indirect
14+
github.com/go-playground/locales v0.14.1 // indirect
15+
github.com/go-playground/universal-translator v0.18.1 // indirect
16+
github.com/go-playground/validator/v10 v10.26.0 // indirect
17+
github.com/goccy/go-json v0.10.5 // indirect
18+
github.com/google/uuid v1.6.0 // indirect
19+
github.com/json-iterator/go v1.1.12 // indirect
20+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
21+
github.com/leodido/go-urn v1.4.0 // indirect
22+
github.com/mattn/go-isatty v0.0.20 // indirect
23+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
24+
github.com/modern-go/reflect2 v1.0.2 // indirect
25+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
26+
github.com/pkg/errors v0.9.1 // indirect
27+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
28+
github.com/ugorji/go/codec v1.2.12 // indirect
29+
golang.org/x/arch v0.16.0 // indirect
30+
golang.org/x/crypto v0.37.0 // indirect
31+
golang.org/x/net v0.39.0 // indirect
32+
golang.org/x/sys v0.32.0 // indirect
33+
golang.org/x/text v0.24.0 // indirect
34+
google.golang.org/protobuf v1.36.6 // indirect
35+
gopkg.in/yaml.v3 v3.0.1 // indirect
36+
)

go.sum

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=
2+
github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
3+
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
4+
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
5+
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
6+
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
7+
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
8+
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
9+
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
10+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12+
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
13+
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
14+
github.com/gin-contrib/cors v1.7.5 h1:cXC9SmofOrRg0w9PigwGlHG3ztswH6bqq4vJVXnvYMk=
15+
github.com/gin-contrib/cors v1.7.5/go.mod h1:4q3yi7xBEDDWKapjT2o1V7mScKDDr8k+jZ0fSquGoy0=
16+
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
17+
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
18+
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
19+
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
20+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
21+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
22+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
23+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
24+
github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=
25+
github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
26+
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
27+
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
28+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
29+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
30+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
31+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
32+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
33+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
34+
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
35+
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
36+
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
37+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
38+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
39+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
40+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
41+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
42+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
43+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
44+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
45+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
46+
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
47+
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
48+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
49+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
50+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
51+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
52+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
53+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
54+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
55+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
56+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
57+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
58+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
59+
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
60+
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
61+
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
62+
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
63+
golang.org/x/arch v0.16.0 h1:foMtLTdyOmIniqWCHjY6+JxuC54XP1fDwx4N0ASyW+U=
64+
golang.org/x/arch v0.16.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE=
65+
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
66+
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
67+
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
68+
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
69+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
70+
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
71+
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
72+
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
73+
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
74+
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
75+
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
76+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
77+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
78+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
79+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
80+
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
81+
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

handler/handler.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package handler
2+
3+
import (
4+
"github.com/gin-contrib/cors"
5+
"github.com/gin-gonic/gin"
6+
"log"
7+
"net/http"
8+
)
9+
10+
var (
11+
pwd string
12+
r *gin.Engine
13+
)
14+
15+
func Handler(port, passwd string) {
16+
pwd = passwd
17+
gin.SetMode(gin.ReleaseMode)
18+
config := cors.DefaultConfig()
19+
config.AllowAllOrigins = true
20+
config.AllowHeaders = []string{"Content-Type", "Authorization"}
21+
config.AllowMethods = []string{"GET", "POST"}
22+
r = gin.New()
23+
r.Use(cors.New(config))
24+
r.GET("/lrc", lyricHandler)
25+
r.NoRoute(func(c *gin.Context) {
26+
c.JSON(http.StatusForbidden, gin.H{})
27+
})
28+
log.Printf("The server will be running on port %s", port)
29+
r.Run(":" + port)
30+
}

0 commit comments

Comments
 (0)