koishi-plugin-bilirice 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +29 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -65,7 +65,9 @@ function apply(ctx, config) {
|
|
|
65
65
|
baseURL: "https://api.live.bilibili.com",
|
|
66
66
|
timeout: finalConfig.timeout,
|
|
67
67
|
headers: {
|
|
68
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
68
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
69
|
+
"Referer": "https://live.bilibili.com/"
|
|
70
|
+
// 添加Referer,避免API拦截
|
|
69
71
|
}
|
|
70
72
|
});
|
|
71
73
|
async function getRoomIdByMid(mid) {
|
|
@@ -92,9 +94,32 @@ function apply(ctx, config) {
|
|
|
92
94
|
__name(getRoomBaseInfo, "getRoomBaseInfo");
|
|
93
95
|
async function getRoomStat(roomId) {
|
|
94
96
|
try {
|
|
95
|
-
const res = await api.get("/room/v1/
|
|
97
|
+
const res = await api.get("/xlive/web-room/v1/index/getInfoByRoom", {
|
|
98
|
+
params: {
|
|
99
|
+
room_id: roomId,
|
|
100
|
+
platform: "web"
|
|
101
|
+
}
|
|
102
|
+
});
|
|
96
103
|
if (res.data.code !== 0) throw new Error(`获取直播间统计失败: ${res.data.message}`);
|
|
97
|
-
|
|
104
|
+
const data = res.data.data;
|
|
105
|
+
const stat = {
|
|
106
|
+
// 核心统计字段(对齐原接口的字段名)
|
|
107
|
+
online: data.room_info.online || 0,
|
|
108
|
+
// 最高在线人数
|
|
109
|
+
watch_num: data.room_info.watch_num || 0,
|
|
110
|
+
// 观看人数
|
|
111
|
+
interact_num: data.room_info.interact_num || 0,
|
|
112
|
+
// 互动数
|
|
113
|
+
dm_count: data.room_info.dm_count || 0,
|
|
114
|
+
// 弹幕数
|
|
115
|
+
medal_count: data.room_info.medal_count || 0,
|
|
116
|
+
// 舰队数
|
|
117
|
+
fans_count: data.anchor_info.base_info.fans_count || 0,
|
|
118
|
+
// 粉丝数
|
|
119
|
+
live_time: data.room_info.live_time || 0
|
|
120
|
+
// 开播时间戳
|
|
121
|
+
};
|
|
122
|
+
return stat;
|
|
98
123
|
} catch (err) {
|
|
99
124
|
ctx.logger.error(`获取直播间统计失败(roomId=${roomId}):`, err);
|
|
100
125
|
throw err;
|
|
@@ -144,7 +169,7 @@ function apply(ctx, config) {
|
|
|
144
169
|
interactCount: currentStat.interact_num,
|
|
145
170
|
dmCount: currentStat.dm_count,
|
|
146
171
|
avgDmPerUser: Number((currentStat.dm_count / Math.max(currentStat.watch_num, 1)).toFixed(2)),
|
|
147
|
-
medalCount: currentStat.medal_count
|
|
172
|
+
medalCount: currentStat.medal_count,
|
|
148
173
|
fansChange,
|
|
149
174
|
endTime
|
|
150
175
|
};
|