diff options
author | Kyomotoi <[email protected]> | 2020-07-26 22:53:16 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-26 22:53:16 +0800 |
commit | 15962441c1371354a6e81855eb1f99568e3bb7f5 (patch) | |
tree | bfc891ba5284284c373d7ceaed48867f4760ce91 | |
parent | 6a4ac285a7955854b8341c20522b0893453c3f3e (diff) | |
download | ATRI-15962441c1371354a6e81855eb1f99568e3bb7f5.tar.gz ATRI-15962441c1371354a6e81855eb1f99568e3bb7f5.tar.bz2 ATRI-15962441c1371354a6e81855eb1f99568e3bb7f5.zip |
Create cloudmusic.py
-rw-r--r-- | ATRIbot/plugins/cloudmusic.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/ATRIbot/plugins/cloudmusic.py b/ATRIbot/plugins/cloudmusic.py new file mode 100644 index 0000000..cbc36d7 --- /dev/null +++ b/ATRIbot/plugins/cloudmusic.py @@ -0,0 +1,87 @@ +import json +import nonebot +from orjson import loads +from html import unescape + +import requests + +def request_api(url): + response = requests.request("GET", url) + html = response.text + return html + + +REPORT_FORMAT = """Status: {status} +Song id: {id} +Br: {br} +Download: {url} +MD5: {md5}""" + + [email protected]_natural_language(only_to_me = False) +async def fk_tx_app_cloudmusic(session: nonebot.NLPSession): + rich_message = [x for x in session.ctx['message'] if x.get('type') == 'rich'] + + if not rich_message: + return + + rich_message = rich_message[0]['data']['content'] + + if '网易云音乐' not in str(rich_message): + return + + if 'music' not in str(rich_message): + return + + data = loads(unescape(rich_message)) + + URL = data['music']['jumpUrl'] + rep = URL.split('/') + wid = rep[4] + + url = f'https://api.imjad.cn/cloudmusic/?type=song&id={wid}&br=320000' + print(url) + + dc = json.loads(response.request_api(url)) + + await session.send( + REPORT_FORMAT.format( + status = dc["code"], + id = dc["data"][0]["id"], + br = dc["data"][0]["br"], + url = dc["data"][0]["url"], + md5 = dc["data"][0]["md5"], + ) + ) + + [email protected]_natural_language(only_to_me = False) +async def cloudmusic_link(session: nonebot.NLPSession): + share_message = [x for x in session.ctx['message'] if x.get('type') == 'share'] + + if not share_message: + return + + share_message = share_message[0]['data']['url'] + + if 'music.163.com' not in str(share_message): + return + + rep = share_message.replace('=', '/') + rep = rep.replace('&', '/') + wid = rep[4] + + url = f'https://api.imjad.cn/cloudmusic/?type=song&id={wid}&br=320000' + print(url) + + dc = json.loads(response.request_api(url)) + + await session.send( + REPORT_FORMAT.format( + status = dc["code"], + id = dc["data"][0]["id"], + br = dc["data"][0]["br"], + url = dc["data"][0]["url"], + md5 = dc["data"][0]["md5"], + ) + ) |