Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
2024-02-22 v1.0.3-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
ZxwyWebSite committed Feb 22, 2024
1 parent 07c32ab commit 0b44b07
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 61 deletions.
15 changes: 13 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const (
args_zpak = true // 打包文件
)

var workDir string

// 编译
func doCompile(v_os, v_arch, v_archv, v_cc string) error {
// 构建 | 目标系统 | 目标架构 | 优化等级 | 不包含调试信息 | 使用外部链接器 | 输出详细操作 | 静态编译 | JSON解释器
Expand All @@ -52,7 +54,11 @@ func doCompile(v_os, v_arch, v_archv, v_cc string) error {
return ztool.Str_FastConcat(name, v_archv, wexe)
}()
pname := filepath.Clean(ztool.Str_FastConcat(args_path, fname))
cmd := ztool.Str_FastConcat(`go build -o `, pname, ` -ldflags "-s -w -linkmode external -extldflags ''" -tags "go_json"`) // go_json | json(std) | jsoniter | sonic
cmd := ztool.Str_FastConcat(
`go build -o `, pname,
` -gcflags=-trimpath="`, workDir, `" -asmflags=-trimpath="`, workDir, `" -buildvcs=false`,
` -ldflags "-s -w -linkmode external" -tags "go_json"`, // go_json | json(std) | jsoniter | sonic
)
// 输出要执行的命令
ztool.Cmd_FastPrintln(ztool.Str_FastConcat(`执行命令:`, cmd))
// 设置环境&执行编译
Expand Down Expand Up @@ -84,7 +90,11 @@ func doCompile(v_os, v_arch, v_archv, v_cc string) error {
if !ztool.Fbj_IsExists(`archieve`) {
os.MkdirAll(filepath.Join(args_path, `archieve`), 0755)
}
if err := ztool.Pak_ZipFile(pname, ztool.Str_FastConcat(filepath.Join(args_path, `archieve`, fname), `.zip`), ztool.Pak_ZipConfig{UnPath: true}); err != nil {
if err := ztool.Pak_ZipFile(
pname,
filepath.Join(args_path, `archieve`, ztool.Str_LastBefore(fname, `.`))+`.zip`,
ztool.Pak_ZipConfig{UnPath: true},
); err != nil {
ztool.Cmd_FastPrintln(ztool.Str_FastConcat(`打包["`, pname, `"]出错:`, err.Error()))
} else {
ztool.Cmd_FastPrintln(ztool.Str_FastConcat(`打包["`, pname, `"]完成`))
Expand All @@ -98,6 +108,7 @@ func init() {
ztool.Cmd_FastPrintln("简易脚本,未对Linux以外系统做适配,请复制执行以下命令编译:\ngo build -ldflags \"-s -w\" -tags \"go_json\"\n如无报错则会在本目录生成名为lx-source的可执行文件。")
os.Exit(1)
}
workDir, _ = os.Getwd()
ztool.Cmd_FastPrintln(ztool.Str_FastConcat(`
================================
| Golang 一键编译脚本
Expand Down
2 changes: 1 addition & 1 deletion src/caches/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *Query) Free() { c.query = ``; query_pool.Put(c) }

// 根据音质判断文件后缀
func rext(q string) string {
if ztool.Chk_IsMatch(q, `128k`, `320k`) /*q == `128k` || q == `320k`*/ {
if /*ztool.Chk_IsMatch(q, `128k`, `320k`)*/ q == `128k` || q == `320k` {
return `mp3`
}
return `flac`
Expand Down
8 changes: 5 additions & 3 deletions src/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
Version = `1.0.3-fix`
Version = `1.0.3-rc1`
)

var (
Expand Down Expand Up @@ -132,8 +132,9 @@ type (
Kg_token string `comment:"field user.token"`
Kg_userId string `comment:"field user.userid"`
// kg lite_sign_in
Kg_Lite_Enable bool `comment:"是否启用概念版自动签到,仅在appid=3116时运行"`
Kg_Lite_Interval int64 `comment:"调用时间,自动刷新"`
Kg_Lite_Enable bool `comment:"是否启用概念版自动签到,仅在appid=3116时运行"`
Kg_Lite_MixId string `comment:"mix_songmid的获取方式, 默认auto, 可以改成一个数字手动"`
Kg_Lite_Interval int64 `comment:"调用时间,自动刷新"`

// tx
Tx_Enable bool `comment:"是否启用小秋源"`
Expand Down Expand Up @@ -244,6 +245,7 @@ var (
Kg_Client_PidVerSec: `57ae12eb6890223e355ccfcb74edf70d`,
Kg_Client_Pid: `2`,
Kg_userId: `0`,
Kg_Lite_MixId: `auto`,

Tx_Enable: false,
Tx_Refresh_Enable: false,
Expand Down
38 changes: 19 additions & 19 deletions src/server/api_music.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ func musicHandler(c *gin.Context) {
loger := env.Loger.NewGroup(`MusicHandler`)
defer loger.Free()
loger.Debug(`s:'%v', m:'%v', id:'%v', q:'%v'`, ps, pm, pid, pq)
// 查询内存缓存
cquery := strings.Join([]string{pm, ps, pid, pq}, `/`)
loger.Debug(`MemoGet: %v`, cquery)
if cdata, ok := env.Cache.Get(cquery); ok {
loger.Debug(`MemoHIT: %q`, cdata)
if cdata == `` {
out.Code = 2
out.Msg = memRej
} else {
out.Msg = memHIT
out.Data = cdata
}
return out
}
// 定位音乐源
var source custom.Source
var active bool // 是否激活(自定义账号)
Expand Down Expand Up @@ -84,12 +70,26 @@ func musicHandler(c *gin.Context) {
out.Msg = sources.ErrDisable
return out
}
// 定位源方法
if !source.Vef(pid) {
if !source.Vef(&pid) {
out.Code = 6
out.Msg = sources.E_VefMusicId
return out
}
// 查询内存缓存
cquery := strings.Join([]string{pm, ps, pid, pq}, `/`)
loger.Debug(`MemoGet: %v`, cquery)
if cdata, ok := env.Cache.Get(cquery); ok {
loger.Debug(`MemoHIT: %q`, cdata)
if cdata == `` {
out.Code = 2
out.Msg = memRej
} else {
out.Msg = memHIT
out.Data = cdata
}
return out
}
// 定位源方法
switch pm {
case `url`, `link`:
// 查询文件缓存
Expand All @@ -102,7 +102,7 @@ func musicHandler(c *gin.Context) {
if cstat {
loger.Debug(`FileGet: %v`, uquery.Query())
if olink := caches.UseCache.Get(uquery); olink != `` {
env.Cache.Set(cquery, olink, 7200)
env.Cache.Set(cquery, olink, sources.C_lx)
out.Msg = cacheHIT
out.Data = olink
return out
Expand All @@ -118,7 +118,7 @@ func musicHandler(c *gin.Context) {
if cstat && active {
loger.Debug(`FileSet: %v`, out.Data)
if link := caches.UseCache.Set(uquery, out.Data.(string)); link != `` {
env.Cache.Set(cquery, link, 7200)
env.Cache.Set(cquery, link, sources.C_lx)
out.Msg = cacheSet
out.Data = link
return out
Expand All @@ -129,7 +129,7 @@ func musicHandler(c *gin.Context) {
}
}
// 无法获取直链 直接返回原链接
env.Cache.Set(cquery, out.Data, 1200)
env.Cache.Set(cquery, out.Data, source.Exp()-300)
return out
}
case `lrc`, `lyric`:
Expand Down
8 changes: 7 additions & 1 deletion src/server/loadpublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ func loadPublic(r *gin.Engine) {
)
}
r.GET(`/lx-custom-source.js`, func(c *gin.Context) {
var mime string
if _, ok := c.GetQuery(`raw`); ok {
mime = `application/octet-stream`
} else {
mime = `text/javascript; charset=utf-8`
}
c.Render(http.StatusOK, render.Data{
ContentType: `text/javascript; charset=utf-8`,
ContentType: mime,
Data: data,
})
})
Expand Down
41 changes: 31 additions & 10 deletions src/sources/custom/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ package custom

import (
"lx-source/src/env"
"lx-source/src/sources"
"lx-source/src/sources/custom/kg"
"lx-source/src/sources/custom/kw"
"lx-source/src/sources/custom/mg"
"lx-source/src/sources/custom/tx"
"lx-source/src/sources/custom/wy"
"strconv"
"strings"
)

type (
// 源定义
UrlFunc func(string, string) (string, string)
LrcFunc func(string) (string, string)
PicFunc func(string) (string, string)
VefFunc func(string) bool
VefFunc func(*string) bool
// 源接口
Source interface {
Url(string, string) (string, string) // 外链
Lrc(string) (string, string) // 歌词
Pic(string) (string, string) // 封面
Vef(string) bool // 验证
Vef(*string) bool // 验证
Exp() int // 缓存
}
)

Expand All @@ -34,6 +37,7 @@ type WrapSource struct {
LrcFunc
PicFunc
VefFunc
ExpData int
}

func (ws *WrapSource) Url(songMid, quality string) (string, string) {
Expand All @@ -45,9 +49,12 @@ func (ws *WrapSource) Lrc(songMid string) (string, string) {
func (ws *WrapSource) Pic(songMid string) (string, string) {
return ws.PicFunc(songMid)
}
func (ws *WrapSource) Vef(songMid string) bool {
func (ws *WrapSource) Vef(songMid *string) bool {
return ws.VefFunc(songMid)
}
func (ws *WrapSource) Exp() int {
return ws.ExpData
}

var (
WySource Source
Expand All @@ -65,45 +72,59 @@ func init() {
UrlFunc: wy.Url,
LrcFunc: notSupport,
PicFunc: notSupport,
VefFunc: func(songMid string) bool {
_, err := strconv.ParseUint(songMid, 10, 0)
VefFunc: func(songMid *string) bool {
_, err := strconv.ParseUint(*songMid, 10, 0)
return err == nil
},
ExpData: sources.C_wy,
}
}
if env.Config.Source.Enable_Mg {
MgSource = &WrapSource{
UrlFunc: mg.Url,
LrcFunc: notSupport,
PicFunc: notSupport,
VefFunc: func(songMid string) bool { return len(songMid) == 11 },
VefFunc: func(songMid *string) bool {
return len(*songMid) == 11
},
ExpData: sources.C_mg,
}
}
if env.Config.Source.Enable_Kw {
KwSource = &WrapSource{
UrlFunc: kw.Url,
LrcFunc: notSupport,
PicFunc: notSupport,
VefFunc: func(songMid string) bool {
_, err := strconv.ParseUint(songMid, 10, 0)
VefFunc: func(songMid *string) bool {
_, err := strconv.ParseUint(*songMid, 10, 0)
return err == nil
},
ExpData: sources.C_kw,
}
}
if env.Config.Source.Enable_Kg {
KgSource = &WrapSource{
UrlFunc: kg.Url,
LrcFunc: notSupport,
PicFunc: notSupport,
VefFunc: func(songMid string) bool { return len(songMid) == 32 },
VefFunc: func(songMid *string) (ok bool) {
if ok = len(*songMid) == 32; ok {
*songMid = strings.ToUpper(*songMid)
}
return
},
ExpData: sources.C_kg,
}
}
if env.Config.Source.Enable_Tx {
TxSource = &WrapSource{
UrlFunc: tx.Url,
LrcFunc: notSupport,
PicFunc: notSupport,
VefFunc: func(songMid string) bool { return len(songMid) == 14 },
VefFunc: func(songMid *string) bool {
return len(*songMid) == 14
},
ExpData: sources.C_tx,
}
}
if env.Config.Source.Enable_Lx {
Expand Down
13 changes: 12 additions & 1 deletion src/sources/custom/kg/musicinfo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kg

import (
"lx-source/src/env"
"net/http"
"strconv"
"strings"
Expand All @@ -10,6 +11,13 @@ import (
)

func getMusicInfo(hash_ string) (info musicInfo, emsg string) {
cquery := strings.Join([]string{`kg`, hash_, `info`}, `/`)
if cdata, ok := env.Cache.Get(cquery); ok {
if cinfo, ok := cdata.(musicInfo); ok {
info = cinfo
return
}
}
body := ztool.Str_FastConcat(
`{"area_code":"1","show_privilege":"1","show_album_info":"1","is_publish":"","appid":1005,"clientver":11451,"mid":"211008","dfid":"-","clienttime":"`,
strconv.FormatInt(time.Now().Unix(), 10),
Expand Down Expand Up @@ -49,5 +57,8 @@ func getMusicInfo(hash_ string) (info musicInfo, emsg string) {
}
return
}
return infoResp.Data[0][0], infoResp.Errmsg
info = infoResp.Data[0][0]
emsg = infoResp.Errmsg
env.Cache.Set(cquery, info, 7200)
return
}
2 changes: 1 addition & 1 deletion src/sources/custom/kg/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Url(songMid, quality string) (ourl, msg string) {
`x-router`: `tracker.kugou.com`,
}
var resp playInfo
err := signRequest(http.MethodGet, url, nil, params, headers, &resp)
err := signRequest(http.MethodGet, url, ``, params, headers, &resp)
if err != nil {
loger.Error(`Request: %s`, err)
msg = sources.ErrHttpReq
Expand Down
Loading

0 comments on commit 0b44b07

Please sign in to comment.