From 2f3febf4b67def443877e6af8c9936e591914a07 Mon Sep 17 00:00:00 2001 From: AAA <35992542+TNTcraftHIM@users.noreply.github.com> Date: Wed, 2 Sep 2020 23:45:49 +0800 Subject: [PATCH] =?UTF-8?q?NeteaseMusic=E6=9B=B4=E6=96=B0=E7=83=AD?= =?UTF-8?q?=E6=AD=8CAPI=E4=B8=8E=E9=80=89=E6=8B=A9=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E9=99=8D=E4=BD=8E=E9=87=8D=E5=A4=8D=E7=8E=87=20(#55)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: TNTcraftHIM --- list.json | 4 ++-- neteasemusic.py | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/list.json b/list.json index 3ae0ca3..03ab5b7 100644 --- a/list.json +++ b/list.json @@ -282,10 +282,10 @@ }, { "name": "neteasemusic", - "version": "3.6", + "version": "3.7", "section": "daily", "maintainer": "TNTcraftHIM", - "size": "27.1 kb", + "size": "27.8 kb", "supported": true, "des-short": "网易云搜歌/随机热歌/点歌", "des": "可以在线搜索并且快速点歌(可回复信息点歌),也支持随机热歌功能,支持解锁VIP/灰色歌曲。命令:nem。" diff --git a/neteasemusic.py b/neteasemusic.py index bebb3d8..8e61fed 100644 --- a/neteasemusic.py +++ b/neteasemusic.py @@ -39,19 +39,34 @@ async def nem(context): return elif context.parameter[0] == "r": # 随机热歌 await context.edit("随机中 . . .") - url = "https://api.vvhan.com/api/rand.music?type=json&sort=%E7%83%AD%E6%AD%8C%E6%A6%9C" for _ in range(20): # 最多重试20次 + apinum = random.randint(0, 1) + apitype = random.randint(0, 1) + if apitype == 0: + apitype = "飙升榜" + else: + apitype = "热歌榜" + if apinum == 0: + url = "https://api.vvhan.com/api/rand.music?type=json&sort=" + apitype + else: + url = "https://api.uomg.com/api/rand.music?sort=" + apitype + "&format=json" + status = False try: - status = False randsong = requests.get(url, headers=headers) if randsong.status_code == 200: randsong = json.loads(randsong.content) - if randsong['success'] is True: + if apinum == 0 and randsong['success'] is True: context.parameter[0] = "id" context.parameter.append( str(randsong['info']['id'])) status = True break + elif apinum == 1 and randsong['code'] == 1: + context.parameter[0] = "id" + context.parameter.append( + str(randsong['data']['url'][45:])) + status = True + break except: continue if status is False: @@ -59,7 +74,7 @@ async def nem(context): sleep(3) await context.delete() return - else: + else: # 错误输入 await context.edit(helptext) return # 整理关键词