From 58631c5b193c845935eec4f529c205549a7c3fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=AA=E5=A5=BD=E5=90=AC=E4=BA=86=E5=90=A7?= <63231787+kirbystudy@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:02:43 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8Fupdate=20music=20(#535)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⚡️update music 添加咪咕点歌 * ⚡️update music 添加咪咕点歌功能 --- plugin/music/selecter.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/plugin/music/selecter.go b/plugin/music/selecter.go index 941cd61c..66cbc903 100644 --- a/plugin/music/selecter.go +++ b/plugin/music/selecter.go @@ -1,4 +1,4 @@ -// Package music QQ音乐、网易云、酷狗、酷我 点歌 +// Package music QQ音乐、网易云、酷狗、酷我、咪咕 点歌 package music import ( @@ -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 "酷狗": @@ -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{