Skip to content

Commit 5381acb

Browse files
authored
feat(plugin): 添加B站视频查询功能
Signed-off-by: GitHub <[email protected]>
1 parent 5fd0ca8 commit 5381acb

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ py main.py
7474

7575
---
7676

77+
## 📓 计划更新 | Plan
78+
79+
- [ ] 细化报错日志 将更多细节公开给用户
80+
- [ ] 检查SSL证书到期时间并通过配置文件里的邮箱推送给管理员
81+
- [ ] 重新内构所有前端页面关联的后端API接口
82+
- [ ] 适配完毕所有Uapis新功能
83+
- [ ] 创建新的工单系统
84+
85+
---
86+
7787
## 🏷️ 其他版本迁移
7888

7989
* v2版本:

plugins/axt_plugin_bilivideo.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import time
2+
3+
from src.Utils.PluginBase import command
4+
from src.Utils.EventClass import GroupMessageEvent
5+
6+
from uapis_extension import post_for_api, get_from_api
7+
8+
9+
__metadata__ = {
10+
"name": "[社区插件]B站视频查询",
11+
"version": "1.0.0",
12+
"author": "AxT-Team",
13+
"description": "从接口请求解析B站视频信息",
14+
"official": False,
15+
}
16+
17+
@command(["bili", "/bili"])
18+
async def bili_handler(event: GroupMessageEvent):
19+
msg = event.content.split(" ")[1] if len(event.content.split(" ")) > 1 else ""
20+
if msg.lower().startswith("bv"):
21+
url = "bvid"
22+
elif msg.lower().startswith("av") or msg.isdigit():
23+
msg = msg.replace("av", "")
24+
url = "aid"
25+
try:
26+
response = await get_from_api(f"/api/v1/social/bilibili/videoinfo?{url}=" + str(msg))
27+
except Exception as e:
28+
await event.reply("视频信息获取失败,请确保您输入了正确的AV/BV号!")
29+
raise
30+
bvid = response["bvid"]
31+
avid = response["aid"]
32+
part = response["videos"]
33+
part_name = response["tname"]
34+
if response["copyright"] == 1:
35+
copyright = "原创"
36+
elif response["copyright"] == 2:
37+
copyright = "转载"
38+
else:
39+
copyright = "未知"
40+
41+
pic = response["pic"]
42+
title = response["title"]
43+
pubtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(response["pubdate"]))
44+
createtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(response["ctime"]))
45+
desc = response["desc"]
46+
duration = str(int(response["duration"] // 60)) + "分" + str(int(response["duration"] % 60)) + "秒"
47+
owner_name = response["owner"]["name"]
48+
owner_mid = response["owner"]["mid"]
49+
stat_view = response["stat"]["view"]
50+
stat_danmaku = response["stat"]["danmaku"]
51+
stat_reply = response["stat"]["reply"]
52+
stat_favorite = response["stat"]["favorite"]
53+
stat_coin = response["stat"]["coin"]
54+
stat_share = response["stat"]["share"]
55+
stat_like = response["stat"]["like"]
56+
57+
returns = f"""视频标题:{response['title']}
58+
视频AV号:av{avid} BV号:{bvid}
59+
分P数:{part} 分区:{part_name}
60+
{copyright} | 时长:{duration}"""
61+
await event.reply(returns)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "AxTBot-Public"
3-
version = "2.1.0+13021"
3+
version = "2.1.0+13033"
44
description = "AxTBot 社区机器人是由 AxT社区 开发并维护的公共、公益性QQ官方机器人,基于QQ开放平台 ,使用 Python 和 FastAPI 构建"
55
authors = [
66
{name = "Shanshui2024", email = "[email protected]"},

0 commit comments

Comments
 (0)