Skip to content

Commit

Permalink
2024-01-18 v1.0.2-b12-d1
Browse files Browse the repository at this point in the history
  • Loading branch information
ZxwyWebSite committed Jan 18, 2024
1 parent ad64fa1 commit 6db6e9e
Show file tree
Hide file tree
Showing 14 changed files with 562 additions and 41 deletions.
12 changes: 6 additions & 6 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.2-b11`
Version = `1.0.2-b12`
)

var (
Expand Down Expand Up @@ -70,8 +70,8 @@ type (
} // `comment:""`
Conf_Custom struct {
// wy (暂未实现)
Wy_Enable bool `comment:"是否开启小芸源"`
// Wy_Cookie string `comment:"账号cookie数据"`
Wy_Enable bool `comment:"是否开启小芸源"`
Wy_Cookie string `comment:"账号cookie数据"`

// mg (暂未实现)
// Mg_Enable bool `comment:"是否开启小蜜源"`
Expand All @@ -80,9 +80,9 @@ type (
Kw_Enable bool `comment:"是否开启小蜗源"`
Kw_Mode string `comment:"接口模式 0: bdapi(需验证), 1: kwdes"`
// kw bdapi
Kw_Bd_Uid string `comment:"user.uid"`
Kw_Bd_Token string `comment:"user.token"`
Kw_Bd_DevId string `comment:"user.device_id"`
Kw_Bd_Uid string `comment:"field user.uid"`
Kw_Bd_Token string `comment:"field user.token"`
Kw_Bd_DevId string `comment:"field user.device_id"`
// kw kwdes
Kw_Des_Type string `comment:"返回格式 0: text, 1: json"`
Kw_Des_Header string `comment:"请求头 User-Agent"`
Expand Down
2 changes: 2 additions & 0 deletions src/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func loadQMap() [][]string {
// 0.wy
if env.Config.Custom.Wy_Enable {
m[0] = defQuality
} else {
m[0] = tstQuality
}
// 1.mg
m[1] = defQuality
Expand Down
14 changes: 7 additions & 7 deletions src/sources/custom/kw/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"io"
"lx-source/src/env"
"lx-source/src/sources"
"lx-source/src/sources/custom/utils"
"net/http"
"strconv"
"strings"
"sync"

"github.com/ZxwyWebSite/ztool"
Expand Down Expand Up @@ -94,7 +94,7 @@ func bdapi(songMid, quality string) (ourl, msg string) {
msg = ztool.Str_FastConcat(`failed: `, resp.Msg)
return
}
ourl = strings.Split(resp.Data.URL, `?`)[0]
ourl = utils.DelQuery(resp.Data.URL) //strings.Split(resp.Data.URL, `?`)[0]
return
}

Expand Down Expand Up @@ -136,11 +136,11 @@ func kwdes(songMid, quality string) (ourl, msg string) {
return
}
realQuality := strconv.Itoa(resp.Data.Bitrate)
if qualityMapReverse[realQuality] != quality {
if realQuality != infoFile.H[:len(infoFile.H)-1] {
msg = sources.E_QNotMatch
return
}
ourl = resp.Data.URL[:strings.Index(resp.Data.URL, `?`)]
ourl = utils.DelQuery(resp.Data.URL) //resp.Data.URL[:strings.Index(resp.Data.URL, `?`)]
return
}
ztool.Net_Request(http.MethodGet, target_url, nil,
Expand All @@ -161,12 +161,12 @@ func kwdes(songMid, quality string) (ourl, msg string) {
}
infoData := mkMap(data)
loger.Debug(`infoData: %+v`, infoData)
realQuality := qualityMapReverse[infoData[`bitrate`]]
if realQuality != quality {
realQuality := infoData[`bitrate`]
if realQuality != infoFile.H[:len(infoFile.H)-1] {
msg = sources.E_QNotMatch
return
}
ourl = infoData[`url`][:strings.Index(infoData[`url`], `?`)]
ourl = utils.DelQuery(infoData[`url`]) //infoData[`url`][:strings.Index(infoData[`url`], `?`)]
return
},
},
Expand Down
13 changes: 7 additions & 6 deletions src/sources/custom/kw/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ var (
H: `4000k`,
},
}
qualityMapReverse = map[string]string{
`128`: sources.Q_128k,
`320`: sources.Q_320k,
`2000`: sources.Q_flac,
`4000`: sources.Q_fl24,
}
// 注:这个还是有规律的,加上或去掉k即可直接比较
// qualityMapReverse = map[string]string{
// `128`: sources.Q_128k,
// `320`: sources.Q_320k,
// `2000`: sources.Q_flac,
// `4000`: sources.Q_fl24,
// }
desheader = map[string]string{
// `User-Agent`: `okhttp/3.10.0`,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package tx

import (
"crypto/md5"
"encoding/hex"
"regexp"
"strings"

"github.com/ZxwyWebSite/ztool"
"github.com/ZxwyWebSite/ztool/x/bytesconv"
"github.com/ZxwyWebSite/ztool/zcypt"
)

func v(b string) string {
Expand Down Expand Up @@ -106,14 +105,14 @@ func t(b string) (res []int) {
return //res
}

func createMD5(s []byte) string {
hash := md5.New()
hash.Write(s)
return hex.EncodeToString(hash.Sum(nil))
}
// func createMD5(s []byte) string {
// hash := md5.New()
// hash.Write(s)
// return hex.EncodeToString(hash.Sum(nil))
// }

func sign(params []byte) string {
md5Str := strings.ToUpper(createMD5(params))
md5Str := strings.ToUpper(zcypt.CreateMD5(params))
h := v(md5Str)
e := c(md5Str)
ls := t(md5Str)
Expand Down
11 changes: 7 additions & 4 deletions src/sources/custom/tx/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tx
import (
"lx-source/src/env"
"lx-source/src/sources"
"strings"

"github.com/ZxwyWebSite/ztool"
"github.com/ZxwyWebSite/ztool/x/bytesconv"
Expand Down Expand Up @@ -133,9 +132,13 @@ func Url(songMid, quality string) (ourl, msg string) {
msg = sources.E_NoLink //`无法获取音乐链接`
return
}
realQuality := strings.Split(infoData.Filename, `.`)[0][:4]
if qualityMapReverse[realQuality] != quality && /*infoBody.TrackInfo.Pay.PayPlay == 0*/ !tryLink {
msg = sources.E_QNotMatch //`实际音质不匹配`
realQuality := ztool.Str_Before(infoData.Filename, `.`)[:4] //strings.Split(infoData.Filename, `.`)[0][:4]
// if qualityMapReverse[realQuality] != quality && /*infoBody.TrackInfo.Pay.PayPlay == 0*/ !tryLink {
// msg = sources.E_QNotMatch //`实际音质不匹配`
// return
// }
if realQuality != infoFile.H && !tryLink {
msg = sources.E_QNotMatch
return
}
ourl = ztool.Str_FastConcat(`https://ws.stream.qqmusic.qq.com/`, infoData.Purl)
Expand Down
20 changes: 10 additions & 10 deletions src/sources/custom/tx/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
fileInfo = map[string]struct {
E string
H string
E string // 扩展名
H string // 专用音质
}{
sources.Q_128k: {
E: `.mp3`,
Expand All @@ -38,14 +38,14 @@ var (
H: `AI00`,
},
}
qualityMapReverse = map[string]string{
`M500`: sources.Q_128k,
`M800`: sources.Q_320k,
`F000`: sources.Q_flac,
`RS01`: sources.Q_fl24,
`Q000`: `dolby`,
`AI00`: `master`,
}
// qualityMapReverse = map[string]string{
// `M500`: sources.Q_128k,
// `M800`: sources.Q_320k,
// `F000`: sources.Q_flac,
// `RS01`: sources.Q_fl24,
// `Q000`: `dolby`,
// `AI00`: `master`,
// }
header = map[string]string{
`Referer`: `https://y.qq.com/`,
}
Expand Down
9 changes: 9 additions & 0 deletions src/sources/custom/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package utils

import (
"github.com/ZxwyWebSite/ztool"
)

// func SizeFormat(size int) string {
// if size < 1024 {
// return ztool.Str_FastConcat(strconv.Itoa(size), `B`)
Expand All @@ -10,3 +14,8 @@ package utils
// }
// return ``
// }

// 删除?号后尾随内容
func DelQuery(str string) string {
return ztool.Str_Before(str, `?`)
}
98 changes: 98 additions & 0 deletions src/sources/custom/wy/encrypt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package wy

import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"

"github.com/ZxwyWebSite/ztool"
"github.com/ZxwyWebSite/ztool/x/bytesconv"
"github.com/ZxwyWebSite/ztool/x/json"
"github.com/ZxwyWebSite/ztool/zcypt"
)

var (
// __all__ = []string{`weEncrypt`, `linuxEncrypt`, `eEncrypt`}
// MODULUS = ztool.Str_FastConcat(
// `00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7`,
// `b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280`,
// `104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932`,
// `575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b`,
// `3ece0462db0a22b8e7`,
// )
// PUBKEY = `010001`
// NONCE = bytesconv.StringToBytes(`0CoJUm6Qyw8W8jud`)
// LINUXKEY = bytesconv.StringToBytes(`rFgB&h#%2?^eDg:Q`)
eapiKey = bytesconv.StringToBytes(`e82ckenh8dichen8`)
ivKey = bytesconv.StringToBytes(`0102030405060708`)
)

func eapiEncrypt(url, text string) map[string][]string {
digest := zcypt.CreateMD5(bytesconv.StringToBytes(ztool.Str_FastConcat(
`nobody`, url, `use`, text, `md5forencrypt`,
)))
data := ztool.Str_FastConcat(
url, `-36cd479b6b5-`, text, `-36cd479b6b5-`, digest,
)
// 注:JSON编码时会自动将[]byte转为string,这里省去一步转换
return map[string][]string{
`params`: {bytesconv.BytesToString(aesEncrypt(bytesconv.StringToBytes(data), eapiKey, false))},
}
}

// crypto.js

func aesEncrypt(text, key []byte, iv bool) []byte {
pad := 16 - len(text)%16
text = append(text, bytes.Repeat([]byte{byte(pad)}, pad)...)
block, _ := aes.NewCipher(key)
// if err != nil {
// panic(err)
// }
var encryptor cipher.BlockMode
if iv {
encryptor = cipher.NewCBCEncrypter(block, ivKey)
} else {
encryptor = zcypt.NewECBEncrypter(block)
}
ciphertext := make([]byte, len(text))
encryptor.CryptBlocks(ciphertext, text)
if iv {
return zcypt.Base64Encode(base64.StdEncoding, ciphertext)
}
return bytes.ToUpper(zcypt.HexEncode(ciphertext))
}

func eapi(url string, object map[string]any) map[string][]string {
text, err := json.Marshal(object)
if err != nil {
panic(err)
}
message := ztool.Str_FastConcat(
`nobody`, url, `use`, bytesconv.BytesToString(text), `md5forencrypt`,
)
digest := zcypt.CreateMD5(bytesconv.StringToBytes(message))
data := bytes.Join(
[][]byte{
bytesconv.StringToBytes(url),
text,
bytesconv.StringToBytes(digest),
},
[]byte{45, 51, 54, 99, 100, 52, 55, 57, 98, 54, 98, 53, 45},
)
return map[string][]string{
`params`: {bytesconv.BytesToString(aesEncrypt(data, eapiKey, false))},
}
}

func decrypt(data []byte) (out []byte) {
dec, err := zcypt.HexDecode(data)
if err == nil {
out, err = zcypt.AesDecrypt(dec, eapiKey)
}
if err != nil {
panic(err)
}
return out
}
Loading

0 comments on commit 6db6e9e

Please sign in to comment.