XZZ/worker/qymusic.py

41 lines
1.4 KiB
Python
Raw Normal View History

2020-08-21 11:26:21 +08:00
from zzcore import StdAns
import requests
2020-08-21 13:22:33 +08:00
import json
2020-08-21 11:26:21 +08:00
class Ans(StdAns):
2020-08-21 12:04:15 +08:00
def GETMSG(self):
if len(self.parms) < 2:
2020-08-21 14:12:52 +08:00
return '不加参数是坏文明!'
2020-08-21 12:04:15 +08:00
url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp'
params = {
'ct': 24,
'qqmusic_ver': 1298,
'new_json': 1,
'remoteplace': 'txt.yqq.song',
'searchid': '',
't': 0,
'aggr': 1,
'cr': 1,
'catZhida': 1,
'loseless': 0,
'flag_qc': 0,
'p': 1,
'n': 20,
'w':self.raw_msg['message'][8:],
}
try:
2020-08-21 13:22:33 +08:00
resp = requests.get(url=url,params=params).text
resp = json.loads(list(resp.split('callback('))[1][:-1])
2020-08-21 12:04:15 +08:00
# print(resp)
if resp['data']['song']['totalnum'] == 0:
2020-08-21 14:12:52 +08:00
return '啊嘞嘞好像没有诶qaq'
2020-08-25 22:54:48 +08:00
# mid = resp['data']['song']['list'][0]['mid']
id = resp['data']['song']['list'][0]['id']
msg = f'[CQ:music,type=qq,id={id}]'
2020-08-23 04:10:37 +08:00
# mname = resp['data']['song']['list'][0]['name']
# msg = '[CQ:share,url=https://y.qq.com/n/yqq/song/' + str(mid) + '.html,title=' + str(mname) + ']'
2020-08-21 12:04:15 +08:00
except Exception as e:
print(e)
2020-08-21 14:12:52 +08:00
msg = '什么东西坏掉了,大概是疼讯吧...不可能是咱!'
2020-08-21 12:04:15 +08:00
return msg