Merge pull request #24 from weilinfox/master

fix qymusic
This commit is contained in:
SiHuan 2020-08-21 14:03:55 +08:00 committed by GitHub
commit 849e44734d

View file

@ -1,36 +1,38 @@
from zzcore import StdAns from zzcore import StdAns
import requests import requests
import json
class Ans(StdAns): class Ans(StdAns):
def GETMSG(self): def GETMSG(self):
if len(self.parms) < 2: if len(self.parms) < 2:
return '歌名都不指定就能搜到歌了?' return '歌名都不指定就能搜到歌了?'
url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp' url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp'
params = { params = {
'ct': 24, 'ct': 24,
'qqmusic_ver': 1298, 'qqmusic_ver': 1298,
'new_json': 1, 'new_json': 1,
'remoteplace': 'txt.yqq.song', 'remoteplace': 'txt.yqq.song',
'searchid': '', 'searchid': '',
't': 0, 't': 0,
'aggr': 1, 'aggr': 1,
'cr': 1, 'cr': 1,
'catZhida': 1, 'catZhida': 1,
'loseless': 0, 'loseless': 0,
'flag_qc': 0, 'flag_qc': 0,
'p': 1, 'p': 1,
'n': 20, 'n': 20,
'w':self.raw_msg['message'][8:], 'w':self.raw_msg['message'][8:],
} }
try: try:
resp = requests.get(url=url,params=params) resp = requests.get(url=url,params=params).text
resp = re.match("callback%((.+)%)", resp).json() resp = json.loads(list(resp.split('callback('))[1][:-1])
if resp['data']['song']['totalnum'] == 0: # print(resp)
return '辣鸡曲库没这首,或者你的关键词有问题' if resp['data']['song']['totalnum'] == 0:
mid = resp['data']['song']['list'][0]['mid'] return '辣鸡曲库没这首,或者你的关键词有问题'
mname = resp['data']['song']['list'][0]['name'] mid = resp['data']['song']['list'][0]['mid']
msg = '[CQ:share,url=https://y.qq.com/n/yqq/song/' + str(mid) + '.html,title=' + str(mname) + ']' mname = resp['data']['song']['list'][0]['name']
except Exception as e: msg = '[CQ:share,url=https://y.qq.com/n/yqq/song/' + str(mid) + '.html,title=' + str(mname) + ']'
print(e) except Exception as e:
msg = '辣鸡q音太弟弟了' print(e)
return msg msg = '辣鸡q音太弟弟了'
return msg