NeteaseMusic更新热歌API与选择方式,降低重复率 (#55)

Co-authored-by: TNTcraftHIM <TNTcraftHIM@users.noreply.github.com>
This commit is contained in:
AAA 2020-09-02 23:45:49 +08:00 committed by GitHub
parent 75a8e46635
commit 2f3febf4b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View File

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

View File

@ -39,19 +39,34 @@ async def nem(context):
return return
elif context.parameter[0] == "r": # 随机热歌 elif context.parameter[0] == "r": # 随机热歌
await context.edit("随机中 . . .") 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次 for _ in range(20): # 最多重试20次
try: 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 status = False
try:
randsong = requests.get(url, headers=headers) randsong = requests.get(url, headers=headers)
if randsong.status_code == 200: if randsong.status_code == 200:
randsong = json.loads(randsong.content) randsong = json.loads(randsong.content)
if randsong['success'] is True: if apinum == 0 and randsong['success'] is True:
context.parameter[0] = "id" context.parameter[0] = "id"
context.parameter.append( context.parameter.append(
str(randsong['info']['id'])) str(randsong['info']['id']))
status = True status = True
break break
elif apinum == 1 and randsong['code'] == 1:
context.parameter[0] = "id"
context.parameter.append(
str(randsong['data']['url'][45:]))
status = True
break
except: except:
continue continue
if status is False: if status is False:
@ -59,7 +74,7 @@ async def nem(context):
sleep(3) sleep(3)
await context.delete() await context.delete()
return return
else: else: # 错误输入
await context.edit(helptext) await context.edit(helptext)
return return
# 整理关键词 # 整理关键词