mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 14:30:10 +08:00
🎨 优化代码格式
This commit is contained in:
parent
52ea7050de
commit
82dbade512
@ -4,23 +4,26 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
zero.OnRegex("^酷我点歌(.+?)$").SetBlock(true).SetPriority(50).Handle(func(ctx *zero.Ctx) {
|
zero.OnRegex("^酷我点歌(.+?)$").SetBlock(true).FirstPriority().
|
||||||
ctx.Send(KuWo(ctx.State["regex_matched"].([]string)[1]))
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
ctx.Send(kuwo(ctx.State["regex_matched"].([]string)[1]))
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
zero.OnRegex("^酷狗点歌(.+?)$").SetBlock(true).SetPriority(50).Handle(func(ctx *zero.Ctx) {
|
zero.OnRegex("^酷狗点歌(.+?)$").SetBlock(true).SetPriority(50).Handle(func(ctx *zero.Ctx) {
|
||||||
ctx.Send(KuGou(ctx.State["regex_matched"].([]string)[1]))
|
ctx.Send(kugou(ctx.State["regex_matched"].([]string)[1]))
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -37,53 +40,95 @@ func init() {
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
func KuWo(KeyWord string) string {
|
// kuwo 返回酷我音乐卡片
|
||||||
headers := map[string]string{
|
func kuwo(keyword string) message.MessageSegment {
|
||||||
"Cookie": "Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1610284708,1610699237; _ga=GA1.2.1289529848.1591618534; kw_token=LWKACV45JSQ; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1610699468; _gid=GA1.2.1868980507.1610699238; _gat=1",
|
headers := http.Header{
|
||||||
"csrf": "LWKACV45JSQ",
|
"Cookie": []string{"Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1610284708,1610699237; _ga=GA1.2.1289529848.1591618534; kw_token=LWKACV45JSQ; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1610699468; _gid=GA1.2.1868980507.1610699238; _gat=1"},
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
|
"csrf": []string{"LWKACV45JSQ"},
|
||||||
"Referer": "https://www.kuwo.cn/search/list?key=",
|
"User-Agent": []string{"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"},
|
||||||
|
"Referer": []string{"https://www.kuwo.cn/search/list?key="},
|
||||||
}
|
}
|
||||||
api := "https://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key="+url.QueryEscape(KeyWord)+"&pn=1&rn=1&httpsStatus=1"
|
// 搜索音乐信息 第一首歌
|
||||||
info := gjson.ParseBytes(NetGet(api,headers)).Get("data.list.0")
|
search, _ := url.Parse("https://www.kuwo.cn/api/www/search/searchMusicBykeyWord")
|
||||||
return fmt.Sprintf("[CQ:music,type=custom,url=%s,audio=%s,title=%s,content=%s,image=%s]",
|
search.RawQuery = url.Values{
|
||||||
|
"key": []string{keyword},
|
||||||
|
"pn": []string{"1"},
|
||||||
|
"rn": []string{"1"},
|
||||||
|
"httpsStatus": []string{"1"},
|
||||||
|
}.Encode()
|
||||||
|
info := gjson.ParseBytes(netGet(search.String(), headers)).Get("data.list.0")
|
||||||
|
// 获得音乐直链
|
||||||
|
music, _ := url.Parse("http://www.kuwo.cn/url")
|
||||||
|
music.RawQuery = url.Values{
|
||||||
|
"format": []string{"mp3"},
|
||||||
|
"rid": []string{fmt.Sprintf("%d", info.Get("rid").Int())},
|
||||||
|
"response": []string{"url"},
|
||||||
|
"type": []string{"convert_url3"},
|
||||||
|
"br": []string{"128kmp3"},
|
||||||
|
"from": []string{"web"},
|
||||||
|
"httpsStatus": []string{"1"},
|
||||||
|
}.Encode()
|
||||||
|
audio := gjson.ParseBytes(netGet(music.String(), headers))
|
||||||
|
// 返回音乐卡片
|
||||||
|
return message.CustomMusic(
|
||||||
fmt.Sprintf("https://www.kuwo.cn/play_detail/%d", info.Get("rid").Int()),
|
fmt.Sprintf("https://www.kuwo.cn/play_detail/%d", info.Get("rid").Int()),
|
||||||
gjson.ParseBytes(
|
audio.Get("url").Str,
|
||||||
NetGet(fmt.Sprintf(
|
|
||||||
"http://www.kuwo.cn/url?format=mp3&rid=%d&response=url&type=convert_url3&br=128kmp3&from=web&httpsStatus=1", info.Get("rid").Int()),headers)).Get("url").Str,
|
|
||||||
info.Get("name").Str,
|
info.Get("name").Str,
|
||||||
info.Get("artist").Str,
|
).Add("content", info.Get("artist").Str).Add("image", info.Get("pic").Str)
|
||||||
info.Get("pic").Str,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func KuGou(KeyWord string) string {
|
// kugou 返回酷狗音乐卡片
|
||||||
|
func kugou(keyword string) message.MessageSegment {
|
||||||
stamp := time.Now().UnixNano() / 1e6
|
stamp := time.Now().UnixNano() / 1e6
|
||||||
api := fmt.Sprintf(
|
hash := GetMd5(
|
||||||
"https://complexsearch.kugou.com/v2/search/song?callback=callback123&keyword=%s&page=1&pagesize=30&bitrate=0&isfuzzy=0&tag=em&inputtype=0&platform=WebFilter&userid=-1&clientver=2000&iscorrection=1&privilege_filter=0&srcappid=2919&clienttime=%d&mid=%d&uuid=%d&dfid=-&signature=%s",
|
fmt.Sprintf(
|
||||||
KeyWord,stamp,stamp,stamp,GetMd5(fmt.Sprintf(
|
|
||||||
"NVPh5oo715z5DIWAeQlhMDsWXXQV4hwtbitrate=0callback=callback123clienttime=%dclientver=2000dfid=-inputtype=0iscorrection=1isfuzzy=0keyword=%smid=%dpage=1pagesize=30platform=WebFilterprivilege_filter=0srcappid=2919tag=emuserid=-1uuid=%dNVPh5oo715z5DIWAeQlhMDsWXXQV4hwt",
|
"NVPh5oo715z5DIWAeQlhMDsWXXQV4hwtbitrate=0callback=callback123clienttime=%dclientver=2000dfid=-inputtype=0iscorrection=1isfuzzy=0keyword=%smid=%dpage=1pagesize=30platform=WebFilterprivilege_filter=0srcappid=2919tag=emuserid=-1uuid=%dNVPh5oo715z5DIWAeQlhMDsWXXQV4hwt",
|
||||||
stamp,KeyWord,stamp,stamp)),
|
stamp, keyword, stamp, stamp,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
res := NetGet(api, map[string]string{"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"})
|
// 搜索音乐信息 第一首歌
|
||||||
|
h1 := http.Header{
|
||||||
|
"User-Agent": []string{"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"},
|
||||||
|
}
|
||||||
|
search, _ := url.Parse("https://complexsearch.kugou.com/v2/search/song")
|
||||||
|
search.RawQuery = url.Values{
|
||||||
|
"callback": []string{"callback123"},
|
||||||
|
"keyword": []string{keyword},
|
||||||
|
"page": []string{"1"},
|
||||||
|
"pagesize": []string{"30"},
|
||||||
|
"bitrate": []string{"0"},
|
||||||
|
"isfuzzy": []string{"0"},
|
||||||
|
"tag": []string{"em"},
|
||||||
|
"inputtype": []string{"0"},
|
||||||
|
"platform": []string{"WebFilter"},
|
||||||
|
"userid": []string{"-1"},
|
||||||
|
"clientver": []string{"2000"},
|
||||||
|
"iscorrection": []string{"1"},
|
||||||
|
"privilege_filter": []string{"0"},
|
||||||
|
"srcappid": []string{"2919"},
|
||||||
|
"clienttime": []string{fmt.Sprintf("%d", stamp)},
|
||||||
|
"mid": []string{fmt.Sprintf("%d", stamp)},
|
||||||
|
"uuid": []string{fmt.Sprintf("%d", stamp)},
|
||||||
|
"dfid": []string{"-"},
|
||||||
|
"signature": []string{hash},
|
||||||
|
}.Encode()
|
||||||
|
res := netGet(search.String(), h1)
|
||||||
info := gjson.ParseBytes(res[12 : len(res)-2]).Get("data.lists.0")
|
info := gjson.ParseBytes(res[12 : len(res)-2]).Get("data.lists.0")
|
||||||
res = NetGet(
|
// 获得音乐直链
|
||||||
fmt.Sprintf("https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash=%s&album_id=%s",info.Get("FileHash").Str,info.Get("AlbumID").Str),
|
h2 := http.Header{
|
||||||
map[string]string{
|
"Cookie": []string{"kg_mid=d8e70a262c93d47599c6196c612d6f4f; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1610278505,1611631363,1611722252; kg_dfid=33ZWee1kircl0jcJ1h0WF1fX; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1611727348; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e"},
|
||||||
"Cookie": "kg_mid=d8e70a262c93d47599c6196c612d6f4f; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1610278505,1611631363,1611722252; kg_dfid=33ZWee1kircl0jcJ1h0WF1fX; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1611727348; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e",
|
"Host": []string{"wwwapi.kugou.com"},
|
||||||
"Host": "wwwapi.kugou.com",
|
"TE": []string{"Trailers"},
|
||||||
"TE": "Trailers",
|
"User-Agent": []string{"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"},
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
|
}
|
||||||
})
|
music := "https://wwwapi.kugou.com/yy/index.php?r=play%2Fgetdata&hash=" + info.Get("FileHash").Str + "&album_id=" + info.Get("AlbumID").Str
|
||||||
jump_url := fmt.Sprintf("https://www.kugou.com/song/#hash=%s&album_id=%s",info.Get("FileHash").Str,info.Get("AlbumID").Str)
|
audio := gjson.ParseBytes(netGet(music, h2)).Get("data")
|
||||||
info = gjson.ParseBytes(res).Get("data")
|
// 返回音乐卡片
|
||||||
return fmt.Sprintf("[CQ:music,type=custom,url=%s,audio=%s,title=%s,content=%s,image=%s]",
|
return message.CustomMusic(
|
||||||
jump_url,
|
"https://www.kugou.com/song/#hash="+audio.Get("hash").Str+"&album_id="+audio.Get("album_id").Str,
|
||||||
strings.Replace(info.Get("play_backup_url").Str,"\\/","/",-1),
|
strings.Replace(audio.Get("play_backup_url").Str, "\\/", "/", -1),
|
||||||
info.Get("song_name").Str,
|
audio.Get("audio_name").Str,
|
||||||
info.Get("author_name").Str,
|
).Add("content", audio.Get("author_name").Str).Add("image", audio.Get("img").Str)
|
||||||
info.Get("img").Str,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func WyCloud(KeyWord string) string {
|
func WyCloud(KeyWord string) string {
|
||||||
@ -133,10 +178,16 @@ func QQMusic(KeyWord string) string {
|
|||||||
|
|
||||||
func StrMidGet(pre string, suf string, str string) string {
|
func StrMidGet(pre string, suf string, str string) string {
|
||||||
n := strings.Index(str, pre)
|
n := strings.Index(str, pre)
|
||||||
if n == -1 {n = 0} else {n = n + len(pre)}
|
if n == -1 {
|
||||||
|
n = 0
|
||||||
|
} else {
|
||||||
|
n = n + len(pre)
|
||||||
|
}
|
||||||
str = string([]byte(str)[n:])
|
str = string([]byte(str)[n:])
|
||||||
m := strings.Index(str, suf)
|
m := strings.Index(str, suf)
|
||||||
if m == -1 {m = len(str)}
|
if m == -1 {
|
||||||
|
m = len(str)
|
||||||
|
}
|
||||||
return string([]byte(str)[:m])
|
return string([]byte(str)[:m])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +201,20 @@ func GetMd5(s string) string {
|
|||||||
func NetGet(get_url string, headers map[string]string) []byte {
|
func NetGet(get_url string, headers map[string]string) []byte {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
request, _ := http.NewRequest("GET", get_url, nil)
|
request, _ := http.NewRequest("GET", get_url, nil)
|
||||||
for key,value := range headers{request.Header.Add(key,value)}
|
for key, value := range headers {
|
||||||
|
request.Header.Add(key, value)
|
||||||
|
}
|
||||||
|
res, _ := client.Do(request)
|
||||||
|
defer res.Body.Close()
|
||||||
|
result, _ := ioutil.ReadAll(res.Body)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// netGet 返回请求数据
|
||||||
|
func netGet(get_url string, header http.Header) []byte {
|
||||||
|
client := &http.Client{}
|
||||||
|
request, _ := http.NewRequest("GET", get_url, nil)
|
||||||
|
request.Header = header
|
||||||
res, _ := client.Do(request)
|
res, _ := client.Do(request)
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
result, _ := ioutil.ReadAll(res.Body)
|
result, _ := ioutil.ReadAll(res.Body)
|
||||||
@ -160,9 +224,13 @@ func NetGet(get_url string,headers map[string]string) []byte {
|
|||||||
func NetPost(post_url string, data map[string]string, headers map[string]string) []byte {
|
func NetPost(post_url string, data map[string]string, headers map[string]string) []byte {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
param := url.Values{}
|
param := url.Values{}
|
||||||
for key,value := range data{param.Set(key,value)}
|
for key, value := range data {
|
||||||
|
param.Set(key, value)
|
||||||
|
}
|
||||||
request, _ := http.NewRequest("POST", post_url, strings.NewReader(param.Encode()))
|
request, _ := http.NewRequest("POST", post_url, strings.NewReader(param.Encode()))
|
||||||
for key,value := range headers{request.Header.Add(key,value)}
|
for key, value := range headers {
|
||||||
|
request.Header.Add(key, value)
|
||||||
|
}
|
||||||
res, _ := client.Do(request)
|
res, _ := client.Do(request)
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
result, _ := ioutil.ReadAll(res.Body)
|
result, _ := ioutil.ReadAll(res.Body)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user