From 4a88fd7c4393ac9655dddbb063f7f3bbc32c2603 Mon Sep 17 00:00:00 2001 From: Ailitonia Date: Thu, 6 May 2021 20:23:49 +0800 Subject: [PATCH] =?UTF-8?q?Upgrade:=20B=E7=AB=99=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E8=A7=86=E9=A2=91=E5=8A=A8=E6=80=81=E5=8F=91?= =?UTF-8?q?=E9=80=81=E5=B0=81=E9=9D=A2=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - B站动态插件视频动态发送封面图片 --- .../bilibili_dynamic_monitor/monitor.py | 18 +++++++++++++----- .../plugins/bilibili_dynamic_monitor/utils.py | 8 +++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/omega_miya/plugins/bilibili_dynamic_monitor/monitor.py b/omega_miya/plugins/bilibili_dynamic_monitor/monitor.py index 66435a4e..52c67f02 100644 --- a/omega_miya/plugins/bilibili_dynamic_monitor/monitor.py +++ b/omega_miya/plugins/bilibili_dynamic_monitor/monitor.py @@ -130,8 +130,8 @@ async def check_dynamic(dy_uid): ) else: origin_dynamic_info = _dy_res.result - # 原动态type=2, 带图片 - if origin_dynamic_info['type'] == 2: + # 原动态type=2 或 8, 带图片 + if origin_dynamic_info['type'] in [2, 8]: # 处理图片序列 pic_segs = '' for pic_url in origin_dynamic_info['origin_pics']: @@ -168,9 +168,17 @@ async def check_dynamic(dy_uid): dynamic_info[num]['name'], dynamic_info[num]['content'], dynamic_info[num]['url']) # 视频 elif dynamic_info[num]['type'] == 8: - msg = '{}发布了新的视频!\n\n《{}》\n“{}”\n{}'.format( - dynamic_info[num]['name'], dynamic_info[num]['origin'], - dynamic_info[num]['content'], dynamic_info[num]['url']) + cover_pic_url = dynamic_info[num].get('cover_pic_url') + _res = await pic_2_base64(cover_pic_url) + pic_seg = MessageSegment.image(_res.result) + if dynamic_info[num]['content']: + msg = '{}发布了新的视频!\n\n《{}》\n“{}”\n{}\n{}'.format( + dynamic_info[num]['name'], dynamic_info[num]['origin'], + dynamic_info[num]['content'], dynamic_info[num]['url'], pic_seg) + else: + msg = '{}发布了新的视频!\n\n《{}》\n{}\n{}'.format( + dynamic_info[num]['name'], dynamic_info[num]['origin'], + dynamic_info[num]['url'], pic_seg) # 小视频 elif dynamic_info[num]['type'] == 16: msg = '{}发布了新的小视频动态!\n\n“{}”\n{}'.format( diff --git a/omega_miya/plugins/bilibili_dynamic_monitor/utils.py b/omega_miya/plugins/bilibili_dynamic_monitor/utils.py index a0263b56..efc4e343 100644 --- a/omega_miya/plugins/bilibili_dynamic_monitor/utils.py +++ b/omega_miya/plugins/bilibili_dynamic_monitor/utils.py @@ -200,7 +200,9 @@ async def get_user_dynamic_history(dy_uid) -> Result.DictResult: # 这是视频的简介和标题 content = card['dynamic'] title = card['title'] - card_dic = dict({'id': dy_id, 'type': 8, 'url': url, + # 这是视频封面 + cover_pic_url = card.get('pic') + card_dic = dict({'id': dy_id, 'type': 8, 'url': url, 'cover_pic_url': cover_pic_url, 'name': name, 'content': content, 'origin': title}) _DYNAMIC_INFO[card_num] = card_dic # type=16, 这是小视频(现在似乎已经失效?) @@ -327,6 +329,10 @@ async def get_dynamic_info(dynamic_id) -> Result.DictResult: origin_description = json.loads(origin_card['card'])['dynamic'] if not origin_description: origin_description = json.loads(origin_card['card'])['title'] + try: + origin_pics_list.append(json.loads(origin_card['card'])['pic']) + except (KeyError, TypeError): + pass elif origin_card['desc']['type'] == 16: origin_description = json.loads(origin_card['card'])['item']['description'] elif origin_card['desc']['type'] == 32: