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 )
0 commit comments