From b4e48fd54bf7b89c1d874b4298257f2b04858c70 Mon Sep 17 00:00:00 2001 From: weilinfox Date: Fri, 21 Aug 2020 12:04:15 +0800 Subject: [PATCH 1/2] try to fix qymusic --- worker/qymusic.py | 66 ++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/worker/qymusic.py b/worker/qymusic.py index 57ffcea..e1119b8 100644 --- a/worker/qymusic.py +++ b/worker/qymusic.py @@ -1,36 +1,38 @@ from zzcore import StdAns import requests +import re class Ans(StdAns): - def GETMSG(self): - if len(self.parms) < 2: - return '歌名都不指定就能搜到歌了?' - 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: - resp = requests.get(url=url,params=params) - resp = re.match("callback%((.+)%)", resp).json() - if resp['data']['song']['totalnum'] == 0: - return '辣鸡曲库没这首,或者你的关键词有问题' - mid = resp['data']['song']['list'][0]['mid'] - mname = resp['data']['song']['list'][0]['name'] - msg = '[CQ:share,url=https://y.qq.com/n/yqq/song/' + str(mid) + '.html,title=' + str(mname) + ']' - except Exception as e: - print(e) - msg = '辣鸡q音,太弟弟了(' - return msg + def GETMSG(self): + if len(self.parms) < 2: + return '歌名都不指定就能搜到歌了?' + 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: + resp = requests.get(url=url,params=params) + # print(resp) + resp = re.match("callback%((.+)%)", resp).json() + if resp['data']['song']['totalnum'] == 0: + return '辣鸡曲库没这首,或者你的关键词有问题' + mid = resp['data']['song']['list'][0]['mid'] + mname = resp['data']['song']['list'][0]['name'] + msg = '[CQ:share,url=https://y.qq.com/n/yqq/song/' + str(mid) + '.html,title=' + str(mname) + ']' + except Exception as e: + print(e) + msg = '辣鸡q音,太弟弟了(' + return msg From 93d367d47432790c5db3557dfe679f861a9b767b Mon Sep 17 00:00:00 2001 From: weilinfox Date: Fri, 21 Aug 2020 13:22:33 +0800 Subject: [PATCH 2/2] fix qymusic --- worker/qymusic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worker/qymusic.py b/worker/qymusic.py index e1119b8..44ffa08 100644 --- a/worker/qymusic.py +++ b/worker/qymusic.py @@ -1,6 +1,6 @@ from zzcore import StdAns import requests -import re +import json class Ans(StdAns): def GETMSG(self): @@ -24,9 +24,9 @@ class Ans(StdAns): 'w':self.raw_msg['message'][8:], } try: - resp = requests.get(url=url,params=params) + resp = requests.get(url=url,params=params).text + resp = json.loads(list(resp.split('callback('))[1][:-1]) # print(resp) - resp = re.match("callback%((.+)%)", resp).json() if resp['data']['song']['totalnum'] == 0: return '辣鸡曲库没这首,或者你的关键词有问题' mid = resp['data']['song']['list'][0]['mid']