NeteaseMusic增加热歌API错误重试

This commit is contained in:
TNTcraftHIM 2020-09-01 16:08:04 +08:00
parent 638a6ea358
commit 622827d1d3
2 changed files with 13 additions and 13 deletions

View File

@ -282,10 +282,10 @@
},
{
"name": "neteasemusic",
"version": "3.4",
"version": "3.5",
"section": "daily",
"maintainer": "TNTcraftHIM",
"size": "27.2 kb",
"size": "27.1 kb",
"supported": true,
"des-short": "网易云搜歌/随机热歌/点歌",
"des": "可以在线搜索并且快速点歌可回复信息点歌也支持随机热歌功能支持解锁VIP/灰色歌曲。命令nem。"

View File

@ -40,20 +40,20 @@ async def nem(context):
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"
randsong = requests.get(url, headers=headers)
for _ in range(20): # 最多重试20次
status = False
if randsong.status_code == 200:
randsong = json.loads(randsong.content)
if randsong['success'] is True:
context.parameter[0] = "id"
try:
context.parameter[1] = str(randsong['info']['id'])
except:
try:
status = False
randsong = requests.get(url, headers=headers)
if randsong.status_code == 200:
randsong = json.loads(randsong.content)
if randsong['success'] is True:
context.parameter[0] = "id"
context.parameter.append(
str(randsong['info']['id']))
status = True
break
status = True
break
except:
continue
if status is False:
await context.edit(apifailtext)
sleep(3)