This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Music.lua
151 lines (147 loc) · 8.43 KB
/
Music.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
local log = require("log")
local Api = require("coreApi")
local json = require("json")
local http = require("http")
function ReceiveFriendMsg(CurrentQQ, data) return 1 end
function ReceiveGroupMsg(CurrentQQ, data)
if string.find(data.Content, "听歌") == 1 then -- 判断一下所接收的消息里是否含有复读机字样 有则进行处理
keyWord = data.Content:gsub("听歌", "") -- 提取关键词 保存到keyWord里
keyWord = keyWord:gsub(" ", "") -- 去除空格
log.notice("听歌keyWord-->%s", keyWord)
if keyWord == "" then return 1 end
local url =
"https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=20&w=" ..
keyWord
log.notice("url-->%s", url)
response, error_message = http.request("GET", url, {
headers = {Accept = "*/*"}
})
local html = response.body
-- log.notice("html-->%s", html)
local str = html:match("callback%((.+)%)")
-- log.notice("str-->%s", str)
local j = json.decode(str)
local songID = ""
local songname = ""
local pic_url = ""
local singer = ""
if j.data and j.data.song and j.data.song.list and j.data.song.list[1] then
songID = j.data.song.list[1].mid
songname = j.data.song.list[1].name
pic_url = j.data.song.list[1].album.pmid
singer = j.data.song.list[1].singer[1].name
log.notice("songID-->%s", songID)
log.notice("songname-->%s", songname)
end
local jumpUrl = "https://y.qq.com/n/yqq/song/" .. songID .. ".html"
pic_url = "http://y.gtimg.cn/music/photo_new/T002R300x300M000" ..
pic_url .. ".jpg?max_age=2592000"
if songID ~= "" then
response, error_message =
http.request( -- https://node-music-api.vercel.app/music/song?songmid=004Z8Ihr0JIu5s&guid=126548448
"GET", "https://node-music-api.vercel.app/music/song", {
query = "guid=126548448&songmid=" .. songID,
headers = {
["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
["Accept-Language"] = "zh-CN,zh;q=0.9,en;q=0.8",
["Connection"] = "keep-alive",
["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}
})
local Json2 = response.body
-- log.notice("Json2-->%s", Json2)
local song = json.decode(Json2)
local song_url = song.data.musicUrl
log.notice("songname>%s", songname)
log.notice("jumpUrl>%s", jumpUrl)
log.notice("pic_url>%s", pic_url)
log.notice("song_url>%s", song_url)
log.notice("singer>%s", singer)
luaPic = Api.Api_SendMsg( -- 调用发消息的接口
CurrentQQ, {
toUser = data.FromGroupId,
sendToType = 2,
sendMsgType = "JsonMsg",
groupid = 0,
content = string.format(
[[{"app":"com.tencent.structmsg","config":{"autosize":true,"ctime":1587018511,"forward":true,"token":"4e1ddb75bc9b780b4eda43d937a9b721","type":"normal"},"desc":"音乐","meta":{"music":{"action":"","android_pkg_name":"","app_type":1,"appid":100497308,"desc":"%s","jumpUrl":"%s","musicUrl":"%s","preview":"%s","sourceMsgId":"0","source_icon":"","source_url":"","tag":"点击图片后台播放","title":"%s"}},"prompt":"[分享]%s","ver":"0.0.0.1","view":"music"}]],
singer, song_url, song_url, pic_url, songname, songname),
atUser = 0
})
end
end
if string.find(data.Content, "点歌") == 1 then -- 判断一下所接收的消息里是否含有复读机字样 有则进行处理
keyWord = data.Content:gsub("点歌", "") -- 提取关键词 保存到keyWord里
-- keyWord = keyWord:gsub(" ", "") -- 去除空格
log.notice("keyWord-->%s", keyWord)
local url =
"https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=20&w=" ..
keyWord
log.notice("url-->%s", url)
if keyWord == "" then return 1 end
response, error_message = http.request("GET", url, {
-- query = "ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=20&w=" ..
-- keyWord,
headers = {Accept = "*/*"}
})
local html = response.body
-- log.notice("html-->%s", html)
local str = html:match("callback%((.+)%)")
-- log.notice("str-->%s", str)
local j = json.decode(str)
local songID = ""
local songname = ""
local pic_url = ""
local singer = ""
if j.data and j.data.song and j.data.song.list and j.data.song.list[1] then
songID = j.data.song.list[1].mid
songname = j.data.song.list[1].name
pic_url = j.data.song.list[1].album.pmid
singer = j.data.song.list[1].singer[1].name
log.notice("songID-->%s", songID)
log.notice("songname-->%s", songname)
end
local jumpUrl = "https://y.qq.com/n/yqq/song/" .. songID .. ".html"
pic_url = "http://y.gtimg.cn/music/photo_new/T002R300x300M000" ..
pic_url .. ".jpg?max_age=2592000"
if songID ~= "" then
response, error_message =
http.request( -- https://node-music-api.vercel.app/music/song?songmid=004Z8Ihr0JIu5s&guid=126548448
"GET", "https://node-music-api.vercel.app/music/song", {
query = "guid=126548448&songmid=" .. songID,
headers = {
["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
["Accept-Language"] = "zh-CN,zh;q=0.9,en;q=0.8",
["Connection"] = "keep-alive",
["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}
})
log.notice("response-->%s", error_message)
local Json2 = response.body
log.notice("Json2-->%s", Json2)
local song = json.decode(Json2)
local song_url = song.data.musicUrl
log.notice("songname>%s", songname)
log.notice("jumpUrl>%s", jumpUrl)
log.notice("pic_url>%s", pic_url)
log.notice("song_url>%s", song_url)
log.notice("singer>%s", singer)
local content = string.format(
"<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID=\"2\" templateID=\"1\" action=\"web\" brief=\"[分享] %s\" sourceMsgId=\"0\" url=\"%s\" flag=\"0\" adverSign=\"0\" multiMsgFlag=\"0\"><item layout=\"2\"><audio cover=\"%s\" src=\"%s\" /><title>%s</title><summary>%s</summary></item><source name=\"QQ音乐\" icon=\"https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png?date=20200503\" url=\"http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856\" action=\"app\" a_actionData=\"com.tencent.qqmusic\" i_actionData=\"tencent1101079856://\" appid=\"1101079856\" /></msg>",
songname, jumpUrl, pic_url, song_url, songname, singer)
content = string.gsub(content, "&", "&")
log.notice("content->%s", content)
luaPic = Api.Api_SendMsg( -- 调用发消息的接口
CurrentQQ, {
toUser = data.FromGroupId,
sendToType = 2,
sendMsgType = "XmlMsg",
groupid = 0,
content = content,
atUser = 0
})
end
end
return 1
end
function ReceiveEvents(CurrentQQ, data, extData) return 1 end