diff options
author | Kyomotoi <[email protected]> | 2020-07-26 22:51:12 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-26 22:51:12 +0800 |
commit | 6a4ac285a7955854b8341c20522b0893453c3f3e (patch) | |
tree | c38faf0c09d1affe31ecf0f753c3f9d8399a1346 | |
parent | fbcb78d75c66276455cc7330778142b6becdc021 (diff) | |
download | ATRI-6a4ac285a7955854b8341c20522b0893453c3f3e.tar.gz ATRI-6a4ac285a7955854b8341c20522b0893453c3f3e.tar.bz2 ATRI-6a4ac285a7955854b8341c20522b0893453c3f3e.zip |
Update bilibili.py
-rw-r--r-- | ATRIbot/plugins/bilibili.py | 119 |
1 files changed, 61 insertions, 58 deletions
diff --git a/ATRIbot/plugins/bilibili.py b/ATRIbot/plugins/bilibili.py index 674b7f8..24960df 100644 --- a/ATRIbot/plugins/bilibili.py +++ b/ATRIbot/plugins/bilibili.py @@ -1,6 +1,16 @@ import json +import nonebot +from orjson import loads +from html import unescape + + import requests -from nonebot import on_command, CommandSession + +def request_api(url): + response = requests.request("GET", url) + html = response.text + return html + REPORT_FORMAT = """({aid})信息如下: @@ -37,60 +47,53 @@ def enc(x): return ''.join(r) -@on_command('bilibili_search_vd', aliases=['b站视频搜索', '批站视频搜索', 'B站视频搜索'], only_to_me=False) -async def bilibili_search_vd(session: CommandSession): - - bi = session.current_arg.strip() - if not bi: - bi = session.get('bi', prompt='请输入bv号或av号') - - str_av = 'av' - str_bv = 'BV' - - if str_av in bi: - aid = bi - elif str_bv in bi: - aid = str(dec(bi)) - print(aid) - else: - await session.finish('检查下bv/av号是否输入错误呢...') - - URL = f'https://api.imjad.cn/bilibili/v2/?aid={aid}' - print(URL) - - ad = 'av' + aid - print(ad) - - try: - response = requests.request("GET", URL) - - try: - html = response.text - mg = json.loads(html) - print('az') - - pic = mg["data"]["pic"] - - await session.send(REPORT_FORMAT.format( - title = mg["data"]["title"], - - view = mg["data"]["stat"]["view"], - coin = mg["data"]["stat"]["coin"], - share = mg["data"]["stat"]["share"], - like = mg["data"]["stat"]["like"], - - bid = mg["data"]["bvid"], - bid_link = mg["data"]["short_link"], - - aid = ad, - aid_link = f'https://b23.tv/{ad}', - - img = f'[CQ:image,file={pic}]', - ) - ) - - except: - await session.send('吾辈在请求数据的时候失败了...') - - except: - await session.send('吾辈一直在努力尝试和主服取得通信ing...ERROR')
\ No newline at end of file [email protected]_natural_language(only_to_me = False) +async def fk_tx_app_bilibili(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'] + + if '小程序' or '哔哩哔哩' not in rich_message['title']: + return + + rich_message = rich_message['content'] + data = loads(unescape(rich_message)) + + if 'detail_1' not in str(rich_message): + return + + URL = data['detail_1']['qqdocurl'] + rep = URL.replace('?', '/') + rep = rep.split('/') + biv = rep[4] + + aid = str(dec(biv)) + + url = f'https://api.imjad.cn/bilibili/v2/?aid={aid}' + ad = 'av' + aid + print(ad) + + dc = json.loads(request_api(url)) + + pic = dc["data"]["pic"] + + await session.send(REPORT_FORMAT.format( + title = dc["data"]["title"], + + view = dc["data"]["stat"]["view"], + coin = dc["data"]["stat"]["coin"], + share = dc["data"]["stat"]["share"], + like = dc["data"]["stat"]["like"], + + bid = biv, + bid_link = dc["data"]["short_link"], + + aid = ad, + aid_link = f'https://b23.tv/{ad}', + + img = f'[CQ:image,file={pic}]', + ) + ) |