From 071d17a5792cd745a89b9c0002ff229f838799d6 Mon Sep 17 00:00:00 2001 From: TNTcraftHIM Date: Tue, 25 Aug 2020 21:16:52 +0800 Subject: [PATCH] =?UTF-8?q?Neteaseshuffle=E5=88=B6=E4=BD=9C=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.json | 10 +++++++ neteaseshuffle.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 neteaseshuffle.py diff --git a/list.json b/list.json index a8c760c..1f93450 100644 --- a/list.json +++ b/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。" } ] } diff --git a/neteaseshuffle.py b/neteaseshuffle.py new file mode 100644 index 0000000..4a84174 --- /dev/null +++ b/neteaseshuffle.py @@ -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()