mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-22 07:47:39 +00:00
Neteaseshuffle制作完成
This commit is contained in:
parent
0c94ecdf43
commit
071d17a579
10
list.json
10
list.json
@ -269,6 +269,16 @@
|
||||
"supported": true,
|
||||
"des-short": "上流对话工具",
|
||||
"des": "让你可以随时放彩虹屁,毒鸡汤,或者变身营销号(迫真,配合-tts食用更佳)。命令:chp,djt,yxh。"
|
||||
},
|
||||
{
|
||||
"name": "neteaseshuffle",
|
||||
"version": "1.0",
|
||||
"section": "daily",
|
||||
"maintainer": "TNTcraftHIM",
|
||||
"size": "3.1 kb",
|
||||
"supported": true,
|
||||
"des-short": "随机网抑热歌",
|
||||
"des": "从热歌榜随机获取一首歌,可以多进程同开,且附带歌曲信息。命令:ns。"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
71
neteaseshuffle.py
Normal file
71
neteaseshuffle.py
Normal file
@ -0,0 +1,71 @@
|
||||
import json
|
||||
import requests
|
||||
from time import sleep
|
||||
from pagermaid.listener import listener
|
||||
from os import remove, path
|
||||
|
||||
|
||||
@listener(is_plugin=True, outgoing=True, command="ns",
|
||||
description="随机网抑云热歌。")
|
||||
async def ns(context):
|
||||
await context.edit("获取中 . . .")
|
||||
try:
|
||||
import eyed3
|
||||
imported = True
|
||||
except ImportError:
|
||||
imported = False
|
||||
await context.edit("获取中 . . .\n(eyeD3支持库未安装,歌曲文件信息将无法导入\n请使用-sh pip3 install eyed3安装,或自行ssh安装)")
|
||||
status = False
|
||||
for _ in range(20): # 最多尝试20次
|
||||
req = requests.get(
|
||||
"http://api.uomg.com/api/rand.music?sort=%E7%83%AD%E6%AD%8C%E6%A6%9C&format=json")
|
||||
if req.status_code == 200:
|
||||
req = json.loads(req.content)
|
||||
songid = req["data"]["url"][45:]
|
||||
music = req['data']['url']
|
||||
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063',
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}
|
||||
music = requests.request("GET", music, headers=headers)
|
||||
name = "/nstmp" + str(req['data']['name']) + ".mp3"
|
||||
with open(name, 'wb') as f:
|
||||
f.write(music.content)
|
||||
if (path.getsize(name) / 1024) < 100:
|
||||
remove(name)
|
||||
continue
|
||||
req = requests.get(
|
||||
"https://api.imjad.cn/cloudmusic/?type=detail&id=" + songid)
|
||||
if req.status_code == 200:
|
||||
req = json.loads(req.content)
|
||||
album = req['songs'][0]['al']['name']
|
||||
albumpic = requests.get(req['songs'][0]['al']['picUrl'])
|
||||
artist = req['songs'][0]['ar'][0]['name']
|
||||
title = req['songs'][0]['name']
|
||||
cap = artist + " - " + title
|
||||
else:
|
||||
continue
|
||||
if imported is True:
|
||||
tag = eyed3.load(name).tag
|
||||
tag.encoding = '\x01'
|
||||
tag.artist = artist
|
||||
tag.title = title
|
||||
tag.album = album
|
||||
tag.images.set(3, albumpic.content, "image/jpeg", u'')
|
||||
tag.save()
|
||||
await context.client.send_file(
|
||||
context.chat_id,
|
||||
name,
|
||||
caption=cap,
|
||||
link_preview=False,
|
||||
force_document=False)
|
||||
status = True
|
||||
break
|
||||
try:
|
||||
remove(name)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
continue
|
||||
if status == False:
|
||||
await context.edit("出错了呜呜呜 ~ 试了好多好多次都无法访问到 API 服务器 。")
|
||||
sleep(2)
|
||||
await context.delete()
|
Loading…
Reference in New Issue
Block a user