Skip to content

Commit

Permalink
Upgrade: B站动态插件视频动态发送封面图片
Browse files Browse the repository at this point in the history
- B站动态插件视频动态发送封面图片
  • Loading branch information
Ailitonia committed May 6, 2021
1 parent 71c49e7 commit 4a88fd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 13 additions & 5 deletions omega_miya/plugins/bilibili_dynamic_monitor/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion omega_miya/plugins/bilibili_dynamic_monitor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 这是小视频(现在似乎已经失效?)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4a88fd7

Please sign in to comment.