Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️update music #535

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions plugin/music/selecter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package music QQ音乐、网易云、酷狗、酷我 点歌
// Package music QQ音乐、网易云、酷狗、酷我、咪咕 点歌
package music

import (
Expand Down Expand Up @@ -28,11 +28,14 @@ func init() {
Help: "- 点歌[xxx]\n" +
"- 网易点歌[xxx]\n" +
"- 酷我点歌[xxx]\n" +
"- 酷狗点歌[xxx]",
"- 酷狗点歌[xxx]\n" +
"- 咪咕点歌[xxx]",
}).OnRegex(`^(.{0,2})点歌\s?(.{1,25})$`).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
// switch 平台
switch ctx.State["regex_matched"].([]string)[1] {
case "咪咕":
ctx.SendChain(migu(ctx.State["regex_matched"].([]string)[2]))
case "酷我":
ctx.SendChain(kuwo(ctx.State["regex_matched"].([]string)[2]))
case "酷狗":
Expand All @@ -45,6 +48,32 @@ func init() {
})
}

// migu 返回咪咕音乐卡片
func migu(keyword string) message.MessageSegment {
headers := http.Header{
"Cookie": []string{"audioplayer_exist=1; audioplayer_open=0; migu_cn_cookie_id=3ad476db-f021-4bda-ab91-c485ac3d56a0; Hm_lvt_ec5a5474d9d871cb3d82b846d861979d=1671119573; Hm_lpvt_ec5a5474d9d871cb3d82b846d861979d=1671119573; WT_FPC=id=279ef92eaf314cbb8d01671116477485:lv=1671119583092:ss=1671116477485"},
"csrf": []string{"LWKACV45JSQ"},
"User-Agent": []string{"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"},
"Referer": []string{"http://m.music.migu.cn"},
"proxy": []string{"false"},
}
// 搜索音乐信息 第一首歌
search, _ := url.Parse("http://m.music.migu.cn/migu/remoting/scr_search_tag")
search.RawQuery = url.Values{
"keyword": []string{keyword},
"type": []string{"2"},
"pgc": []string{"1"},
"rows": []string{"10"},
}.Encode()
info := gjson.ParseBytes(netGet(search.String(), headers)).Get("musics.0")
// 返回音乐卡片
return message.CustomMusic(
fmt.Sprintf("https://music.migu.cn/v3/music/song/%s", info.Get("copyrightId").String()),
info.Get("mp3").String(),
info.Get("songName").String(),
).Add("content", info.Get("artist").Str).Add("image", info.Get("cover").Str).Add("subtype", "migu")
}

// kuwo 返回酷我音乐卡片
func kuwo(keyword string) message.MessageSegment {
headers := http.Header{
Expand Down