koishi-plugin-bilibili-videolink-analysis 1.3.2 → 1.3.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.d.ts +3 -1
- package/lib/index.js +165 -20
- package/lib/utils.d.ts +14 -0
- package/package.json +26 -26
- package/src/index.ts +359 -354
- package/src/utils.ts +223 -18
package/lib/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const name = "bilibili-videolink-analysis";
|
|
|
3
3
|
export declare const inject: {
|
|
4
4
|
optional: string[];
|
|
5
5
|
};
|
|
6
|
-
export declare const usage = "\n\n<h2>\u2192 <a href=\"https://www.npmjs.com/package/koishi-plugin-bilibili-videolink-analysis\" target=\"_blank\">\u53EF\u4EE5\u70B9\u51FB\u8FD9\u91CC\u67E5\u770B\u8BE6\u7EC6\u7684\u6587\u6863\u8BF4\u660E\u2728</a></h2>\n\n\u2728 \u53EA\u9700\u5F00\u542F\u63D2\u4EF6\uFF0C\u5C31\u53EF\u4EE5\u89E3\u6790B\u7AD9\u89C6\u9891\u7684\u94FE\u63A5\u5566~ \u2728\n\n\u5411bot\u53D1\u9001B\u7AD9\u89C6\u9891\u94FE\u63A5\u5427~\n\n\u4F1A\u8FD4\u56DE\u89C6\u9891\u4FE1\u606F\u4E0E\u89C6\u9891\u54E6\n\n---\n\n#### \u26A0\uFE0F **\u5982\u679C\u4F60\u4F7F\u7528\u4E0D\u4E86\u672C\u9879\u76EE\uFF0C\u8BF7\u4F18\u5148\u68C0\u67E5\uFF1A** \u26A0\uFE0F\n#### \u82E5\u65E0\u6CE8\u518C\u7684\u6307\u4EE4\uFF0C\u8BF7\u5173\u5F00\u4E00\u4E0B[command\u63D2\u4EF6](/market?keyword=commands+email:shigma10826@gmail.com)\uFF08\u6CA1\u6709\u6307\u4EE4\u4E5F\u4E0D\u5F71\u54CD\u89E3\u6790\u522B\u4EBA\u7684\u94FE\u63A5\uFF09\n#### \u89C6\u9891\u5185\u5BB9\u662F\u5426\u4E3AB\u7AD9\u7684\u5927\u4F1A\u5458\u4E13\u5C5E\u89C6\u9891/\u4ED8\u8D39\u89C6\u9891/\u5145\u7535\u4E13\u5C5E\u89C6\u9891\n#### \u63A5\u5165\u65B9\u6CD5\u662F\u5426\u652F\u6301\u83B7\u53D6\u7F51\u5740\u94FE\u63A5/\u5C0F\u7A0B\u5E8F\u5361\u7247\u6D88\u606F\n#### \u63A5\u5165\u65B9\u6CD5\u662F\u5426\u652F\u6301\u89C6\u9891\u5143\u7D20\u7684\u53D1\u9001\n#### \u53D1\u9001\u89C6\u9891\u8D85\u65F6/\u5176\u4ED6\u7F51\u7EDC\u95EE\u9898\n#### \u89C6\u9891\u5185\u5BB9\u88AB\u5E73\u53F0\u5C4F\u853D/\u5176\u4ED6\u5E73\u53F0\u56E0\u7D20\n\n---\n\n### \u6CE8\u610F\uFF0C\u70B9\u64AD\u529F\u80FD\u9700\u8981\u4F7F\u7528 puppeteer \u670D\u52A1\n\n\u70B9\u64AD\u529F\u80FD\u662F\u4E3A\u4E86\u65B9\u4FBF\u7FA4\u53CB\u4E00\u8D77\u5237B\u7AD9\u54E6~\n\n\u6BD4\u5982\uFF1A\u641C\u7D22 \u201C\u9060\u3044\u7A7A\u3078\u201D \u7684\u7B2C\u4E8C\u9875\uFF0C\u5E76\u4E14\u7ED3\u679C\u4EE5\u8BED\u97F3\u683C\u5F0F\u8FD4\u56DE\n\n\u793A\u4F8B\uFF1A`\u70B9\u64AD \u9060\u3044\u7A7A\u3078 -a -p 2
|
|
6
|
+
export declare const usage = "\n\n<h2>\u2192 <a href=\"https://www.npmjs.com/package/koishi-plugin-bilibili-videolink-analysis\" target=\"_blank\">\u53EF\u4EE5\u70B9\u51FB\u8FD9\u91CC\u67E5\u770B\u8BE6\u7EC6\u7684\u6587\u6863\u8BF4\u660E\u2728</a></h2>\n\n\u2728 \u53EA\u9700\u5F00\u542F\u63D2\u4EF6\uFF0C\u5C31\u53EF\u4EE5\u89E3\u6790B\u7AD9\u89C6\u9891\u7684\u94FE\u63A5\u5566~ \u2728\n\n\u5411bot\u53D1\u9001B\u7AD9\u89C6\u9891\u94FE\u63A5\u5427~\n\n\u4F1A\u8FD4\u56DE\u89C6\u9891\u4FE1\u606F\u4E0E\u89C6\u9891\u54E6\n\n---\n\n#### \u26A0\uFE0F **\u5982\u679C\u4F60\u4F7F\u7528\u4E0D\u4E86\u672C\u9879\u76EE\uFF0C\u8BF7\u4F18\u5148\u68C0\u67E5\uFF1A** \u26A0\uFE0F\n#### \u82E5\u65E0\u6CE8\u518C\u7684\u6307\u4EE4\uFF0C\u8BF7\u5173\u5F00\u4E00\u4E0B[command\u63D2\u4EF6](/market?keyword=commands+email:shigma10826@gmail.com)\uFF08\u6CA1\u6709\u6307\u4EE4\u4E5F\u4E0D\u5F71\u54CD\u89E3\u6790\u522B\u4EBA\u7684\u94FE\u63A5\uFF09\n#### \u89C6\u9891\u5185\u5BB9\u662F\u5426\u4E3AB\u7AD9\u7684\u5927\u4F1A\u5458\u4E13\u5C5E\u89C6\u9891/\u4ED8\u8D39\u89C6\u9891/\u5145\u7535\u4E13\u5C5E\u89C6\u9891\n#### \u63A5\u5165\u65B9\u6CD5\u662F\u5426\u652F\u6301\u83B7\u53D6\u7F51\u5740\u94FE\u63A5/\u5C0F\u7A0B\u5E8F\u5361\u7247\u6D88\u606F\n#### \u63A5\u5165\u65B9\u6CD5\u662F\u5426\u652F\u6301\u89C6\u9891\u5143\u7D20\u7684\u53D1\u9001\n#### \u53D1\u9001\u89C6\u9891\u8D85\u65F6/\u5176\u4ED6\u7F51\u7EDC\u95EE\u9898\n#### \u89C6\u9891\u5185\u5BB9\u88AB\u5E73\u53F0\u5C4F\u853D/\u5176\u4ED6\u5E73\u53F0\u56E0\u7D20\n\n---\n\n### \u6CE8\u610F\uFF0C\u70B9\u64AD\u529F\u80FD\u9700\u8981\u4F7F\u7528 puppeteer \u670D\u52A1\n\n\u70B9\u64AD\u529F\u80FD\u662F\u4E3A\u4E86\u65B9\u4FBF\u7FA4\u53CB\u4E00\u8D77\u5237B\u7AD9\u54E6~\n\n\u6BD4\u5982\uFF1A\u641C\u7D22 \u201C\u9060\u3044\u7A7A\u3078\u201D \u7684\u7B2C\u4E8C\u9875\uFF0C\u5E76\u4E14\u7ED3\u679C\u4EE5\u8BED\u97F3\u683C\u5F0F\u8FD4\u56DE\n\n\u793A\u4F8B\uFF1A`\u70B9\u64AD \u9060\u3044\u7A7A\u3078 -a -p 2`\n\n\n---\n\n### \u7279\u522B\u9E23\u8C22 \uD83D\uDC96\n\n\u7279\u522B\u9E23\u8C22\u4EE5\u4E0B\u9879\u76EE\u7684\u652F\u6301\uFF1A\n\n- [@summonhim/koishi-plugin-bili-parser](/market?keyword=bili-parser)\n\n---\n\n";
|
|
7
7
|
export interface Config {
|
|
8
8
|
demand: boolean;
|
|
9
9
|
timeout?: number;
|
|
@@ -34,11 +34,13 @@ export interface Config {
|
|
|
34
34
|
bVideoShowIntroductionTofixed: number;
|
|
35
35
|
isfigure: boolean;
|
|
36
36
|
filebuffer: boolean;
|
|
37
|
+
maxFileSizeMB: number;
|
|
37
38
|
middleware: boolean;
|
|
38
39
|
userAgent: string;
|
|
39
40
|
pageclose: boolean;
|
|
40
41
|
loggerinfo: boolean;
|
|
41
42
|
loggerinfofulljson: boolean;
|
|
43
|
+
bufferDelay: number;
|
|
42
44
|
}
|
|
43
45
|
export declare const Config: Schema<Schemastery.ObjectS<{
|
|
44
46
|
demand: Schema<boolean, boolean>;
|
package/lib/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var import_koishi2 = require("koishi");
|
|
|
32
32
|
// src/utils.ts
|
|
33
33
|
var import_koishi = require("koishi");
|
|
34
34
|
var BilibiliParser = class {
|
|
35
|
+
// 是否正在处理 Session
|
|
35
36
|
constructor(ctx, config, logger2) {
|
|
36
37
|
this.ctx = ctx;
|
|
37
38
|
this.config = config;
|
|
@@ -41,6 +42,20 @@ var BilibiliParser = class {
|
|
|
41
42
|
__name(this, "BilibiliParser");
|
|
42
43
|
}
|
|
43
44
|
lastProcessedUrls = {};
|
|
45
|
+
processingQueue = [];
|
|
46
|
+
// 待处理队列
|
|
47
|
+
isProcessing = false;
|
|
48
|
+
// 是否正在处理
|
|
49
|
+
bufferQueue = [];
|
|
50
|
+
// 缓冲队列
|
|
51
|
+
bufferTimer = null;
|
|
52
|
+
// 缓冲定时器
|
|
53
|
+
// Session 级别的队列控制
|
|
54
|
+
sessionQueue = [];
|
|
55
|
+
// Session 缓冲队列
|
|
56
|
+
sessionTimer = null;
|
|
57
|
+
// Session 缓冲定时器
|
|
58
|
+
isProcessingSession = false;
|
|
44
59
|
logInfo(...args) {
|
|
45
60
|
if (this.config.loggerinfo) {
|
|
46
61
|
this.logger.info(...args);
|
|
@@ -96,8 +111,121 @@ var BilibiliParser = class {
|
|
|
96
111
|
}
|
|
97
112
|
return false;
|
|
98
113
|
}
|
|
114
|
+
// 添加 session 到缓冲队列(middleware 入口调用)
|
|
115
|
+
async queueSession(session, sessioncontent) {
|
|
116
|
+
this.sessionQueue.push({ session, sessioncontent, timestamp: Date.now() });
|
|
117
|
+
this.logInfo(`收到消息,Session缓冲区任务数: ${this.sessionQueue.length}`);
|
|
118
|
+
if (this.sessionTimer) {
|
|
119
|
+
clearTimeout(this.sessionTimer);
|
|
120
|
+
}
|
|
121
|
+
this.sessionTimer = setTimeout(() => {
|
|
122
|
+
this.flushSessionBuffer();
|
|
123
|
+
}, this.config.bufferDelay * 1e3);
|
|
124
|
+
}
|
|
125
|
+
// 将 session 缓冲区的任务转移到处理队列
|
|
126
|
+
flushSessionBuffer() {
|
|
127
|
+
if (this.sessionQueue.length === 0) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.logInfo(`Session缓冲时间结束,开始处理 ${this.sessionQueue.length} 个消息`);
|
|
131
|
+
if (!this.isProcessingSession) {
|
|
132
|
+
this.processSessionQueue();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// 处理 session 队列中的任务
|
|
136
|
+
async processSessionQueue() {
|
|
137
|
+
if (this.isProcessingSession || this.sessionQueue.length === 0) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this.isProcessingSession = true;
|
|
141
|
+
this.logInfo(`开始处理Session队列,总任务数: ${this.sessionQueue.length}`);
|
|
142
|
+
while (this.sessionQueue.length > 0) {
|
|
143
|
+
const task = this.sessionQueue.shift();
|
|
144
|
+
this.logInfo(`处理Session (剩余: ${this.sessionQueue.length})`);
|
|
145
|
+
try {
|
|
146
|
+
await this.processSessionTask(task.session, task.sessioncontent);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
this.logger.error("处理Session任务时发生错误:", error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
this.isProcessingSession = false;
|
|
152
|
+
this.logInfo("Session队列处理完成");
|
|
153
|
+
}
|
|
154
|
+
// 实际处理单个 session 任务
|
|
155
|
+
async processSessionTask(session, sessioncontent) {
|
|
156
|
+
this.logger.info(`[队列] 开始处理消息: ${sessioncontent.substring(0, 50)}...`);
|
|
157
|
+
const links = await this.isProcessLinks(sessioncontent);
|
|
158
|
+
if (!links) {
|
|
159
|
+
this.logger.info(`[队列] 未检测到链接`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.logger.info(`[队列] 检测到 ${links.length} 个链接`);
|
|
163
|
+
for (let i = 0; i < links.length; i++) {
|
|
164
|
+
const link = links[i];
|
|
165
|
+
this.logger.info(`[队列] 处理第 ${i + 1}/${links.length} 个链接`);
|
|
166
|
+
const ret = await this.extractLinks(session, [link]);
|
|
167
|
+
if (ret && !this.isLinkProcessedRecently(ret, session.channelId)) {
|
|
168
|
+
this.logger.info(`[队列] 开始下载视频`);
|
|
169
|
+
await this.processVideoTask(session, ret, { video: true });
|
|
170
|
+
this.logger.info(`[队列] 视频处理完成`);
|
|
171
|
+
} else {
|
|
172
|
+
this.logger.info(`[队列] 链接已处理过,跳过`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
this.logger.info(`[队列] Session 处理完成`);
|
|
176
|
+
}
|
|
177
|
+
// 添加任务到缓冲区(已废弃,保留兼容性)
|
|
99
178
|
async processVideoFromLink(session, ret, options = { video: true }) {
|
|
179
|
+
this.bufferQueue.push({ session, ret, options, timestamp: Date.now() });
|
|
180
|
+
this.logInfo(`收到解析请求,缓冲区任务数: ${this.bufferQueue.length}`);
|
|
181
|
+
if (this.bufferTimer) {
|
|
182
|
+
clearTimeout(this.bufferTimer);
|
|
183
|
+
}
|
|
184
|
+
this.bufferTimer = setTimeout(() => {
|
|
185
|
+
this.flushBuffer();
|
|
186
|
+
}, this.config.bufferDelay * 1e3);
|
|
187
|
+
}
|
|
188
|
+
// 将缓冲区的任务转移到处理队列
|
|
189
|
+
flushBuffer() {
|
|
190
|
+
if (this.bufferQueue.length === 0) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
this.logInfo(`缓冲时间结束,将 ${this.bufferQueue.length} 个任务加入处理队列`);
|
|
194
|
+
while (this.bufferQueue.length > 0) {
|
|
195
|
+
const task = this.bufferQueue.shift();
|
|
196
|
+
this.processingQueue.push({
|
|
197
|
+
session: task.session,
|
|
198
|
+
ret: task.ret,
|
|
199
|
+
options: task.options
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (!this.isProcessing) {
|
|
203
|
+
this.processQueue();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// 处理队列中的任务
|
|
207
|
+
async processQueue() {
|
|
208
|
+
if (this.isProcessing || this.processingQueue.length === 0) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this.isProcessing = true;
|
|
212
|
+
this.logInfo(`开始处理队列,总任务数: ${this.processingQueue.length}`);
|
|
213
|
+
while (this.processingQueue.length > 0) {
|
|
214
|
+
const task = this.processingQueue.shift();
|
|
215
|
+
this.logInfo(`处理任务 (剩余: ${this.processingQueue.length})`);
|
|
216
|
+
try {
|
|
217
|
+
await this.processVideoTask(task.session, task.ret, task.options);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
this.logger.error("处理视频任务时发生错误:", error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
this.isProcessing = false;
|
|
223
|
+
this.logInfo("队列处理完成");
|
|
224
|
+
}
|
|
225
|
+
// 实际处理单个视频任务
|
|
226
|
+
async processVideoTask(session, ret, options = { video: true }) {
|
|
100
227
|
const lastretUrl = this.extractLastUrl(ret);
|
|
228
|
+
this.logInfo(`处理视频: ${lastretUrl}`);
|
|
101
229
|
let waitTipMsgId = null;
|
|
102
230
|
if (this.config.waitTip_Switch) {
|
|
103
231
|
const result = await session.send(`${import_koishi.h.quote(session.messageId)}${this.config.waitTip_Switch}`);
|
|
@@ -134,7 +262,6 @@ var BilibiliParser = class {
|
|
|
134
262
|
const { bvid, cid, video } = responseData.data;
|
|
135
263
|
const bilibiliUrl = `https://api.bilibili.com/x/player/playurl?fnval=80&cid=${cid}&bvid=${bvid}`;
|
|
136
264
|
const playData = await this.ctx.http.get(bilibiliUrl);
|
|
137
|
-
this.logInfo(bilibiliUrl);
|
|
138
265
|
if (playData.code === 0 && playData.data && playData.data.dash && playData.data.dash.duration) {
|
|
139
266
|
const videoDurationSeconds = playData.data.dash.duration;
|
|
140
267
|
const videoDurationMinutes = videoDurationSeconds / 60;
|
|
@@ -172,22 +299,40 @@ var BilibiliParser = class {
|
|
|
172
299
|
}
|
|
173
300
|
} else {
|
|
174
301
|
let videoData = video.url;
|
|
175
|
-
this.logInfo(videoData);
|
|
176
302
|
if (this.config.filebuffer) {
|
|
177
303
|
try {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
304
|
+
const response = await fetch(video.url, {
|
|
305
|
+
headers: {
|
|
306
|
+
"User-Agent": this.config.userAgent,
|
|
307
|
+
"Referer": "https://www.bilibili.com/"
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
if (!response.ok) {
|
|
311
|
+
throw new Error(`HTTP ${response.status}`);
|
|
312
|
+
}
|
|
313
|
+
const contentLength = response.headers.get("content-length");
|
|
314
|
+
const fileSizeMB = contentLength ? parseInt(contentLength) / 1024 / 1024 : 0;
|
|
315
|
+
this.logger.info(`[下载] 视频大小: ${fileSizeMB.toFixed(2)}MB`);
|
|
316
|
+
const maxSize = this.config.maxFileSizeMB;
|
|
317
|
+
this.logger.info(`[下载] 配置的最大大小: ${maxSize}MB`);
|
|
318
|
+
if (maxSize > 0 && fileSizeMB > maxSize) {
|
|
319
|
+
this.logger.warn(`[下载] 文件过大 (${fileSizeMB.toFixed(2)}MB > ${maxSize}MB),使用直链模式`);
|
|
320
|
+
videoData = video.url;
|
|
321
|
+
} else {
|
|
322
|
+
this.logger.info(`[下载] 开始下载并转换为Base64...`);
|
|
323
|
+
const contentType = response.headers.get("content-type");
|
|
324
|
+
const mimeType = contentType ? contentType.split(";")[0].trim() : "video/mp4";
|
|
325
|
+
this.logger.info(`[下载] 读取响应体...`);
|
|
326
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
327
|
+
this.logger.info(`[下载] 创建Buffer...`);
|
|
328
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
329
|
+
this.logger.info(`[下载] 转换为Base64...`);
|
|
183
330
|
const base64Data = buffer.toString("base64");
|
|
184
331
|
videoData = `data:${mimeType};base64,${base64Data}`;
|
|
185
|
-
this.
|
|
186
|
-
} else {
|
|
187
|
-
this.logInfo("文件数据无效,使用原始URL");
|
|
332
|
+
this.logger.info(`[下载] 视频下载完成,已转换为Base64`);
|
|
188
333
|
}
|
|
189
334
|
} catch (error) {
|
|
190
|
-
this.logger.error("
|
|
335
|
+
this.logger.error("下载视频失败:", error);
|
|
191
336
|
}
|
|
192
337
|
}
|
|
193
338
|
if (videoData) {
|
|
@@ -503,7 +648,7 @@ var usage = `
|
|
|
503
648
|
|
|
504
649
|
比如:搜索 “遠い空へ” 的第二页,并且结果以语音格式返回
|
|
505
650
|
|
|
506
|
-
示例:\`点播 遠い空へ -a -p 2\`
|
|
651
|
+
示例:\`点播 遠い空へ -a -p 2\`
|
|
507
652
|
|
|
508
653
|
|
|
509
654
|
---
|
|
@@ -587,6 +732,8 @@ var Config = import_koishi2.Schema.intersect([
|
|
|
587
732
|
bVideoShowIntroductionTofixed: import_koishi2.Schema.number().default(50).description("视频的`简介`最大的字符长度<br>超出部分会使用 `...` 代替"),
|
|
588
733
|
isfigure: import_koishi2.Schema.boolean().default(false).description("是否开启合并转发 `仅支持 onebot 适配器` 其他平台开启 无效").experimental(),
|
|
589
734
|
filebuffer: import_koishi2.Schema.boolean().default(true).description("是否将视频链接下载后再发送 (以解决部分onebot协议端的问题)<br>否则使用视频直链发送").experimental(),
|
|
735
|
+
maxFileSizeMB: import_koishi2.Schema.number().default(50).description("文件缓冲最大大小(MB)<br>超过此大小的视频将使用直链发送,避免内存溢出<br>设置为0表示不限制").min(0).max(200),
|
|
736
|
+
bufferDelay: import_koishi2.Schema.number().default(5).description("消息接收缓冲延迟(秒)<br>收到链接后等待指定时间,收集同时发送的多个链接后再逐个处理").min(0).max(30),
|
|
590
737
|
middleware: import_koishi2.Schema.boolean().default(false).description("前置中间件模式"),
|
|
591
738
|
userAgent: import_koishi2.Schema.string().description("所有 API 请求所用的 User-Agent").default("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36")
|
|
592
739
|
}),
|
|
@@ -629,10 +776,7 @@ function apply(ctx, config) {
|
|
|
629
776
|
}
|
|
630
777
|
const links = await bilibiliParser.isProcessLinks(sessioncontent);
|
|
631
778
|
if (links) {
|
|
632
|
-
|
|
633
|
-
if (ret && !bilibiliParser.isLinkProcessedRecently(ret, session.channelId)) {
|
|
634
|
-
await bilibiliParser.processVideoFromLink(session, ret);
|
|
635
|
-
}
|
|
779
|
+
await bilibiliParser.queueSession(session, sessioncontent);
|
|
636
780
|
}
|
|
637
781
|
return next();
|
|
638
782
|
}, config.middleware);
|
|
@@ -650,9 +794,9 @@ function apply(ctx, config) {
|
|
|
650
794
|
});
|
|
651
795
|
await page.addStyleTag({
|
|
652
796
|
content: `
|
|
653
|
-
div.bili-header,
|
|
654
|
-
div.login-tip,
|
|
655
|
-
div.v-popover,
|
|
797
|
+
div.bili-header,
|
|
798
|
+
div.login-tip,
|
|
799
|
+
div.v-popover,
|
|
656
800
|
div.right-entry__outside {
|
|
657
801
|
display: none !important;
|
|
658
802
|
}
|
|
@@ -732,7 +876,8 @@ overlay.style.top = ${config.point[0]}%
|
|
|
732
876
|
overlay.style.left = ${config.point[1]}%`);
|
|
733
877
|
bilibiliParser.logInfo(`用户选择了序号 ${choiceIndex + 1}: ID - ${chosenVideo.id}`);
|
|
734
878
|
if (config.enable) {
|
|
735
|
-
const
|
|
879
|
+
const link = { type: "Video", id: chosenVideo.id };
|
|
880
|
+
const ret = await bilibiliParser.extractLinks(session, [link]);
|
|
736
881
|
if (ret && !bilibiliParser.isLinkProcessedRecently(ret, session.channelId)) {
|
|
737
882
|
await bilibiliParser.processVideoFromLink(session, ret, options);
|
|
738
883
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -5,6 +5,13 @@ export declare class BilibiliParser {
|
|
|
5
5
|
private config;
|
|
6
6
|
private logger;
|
|
7
7
|
private lastProcessedUrls;
|
|
8
|
+
private processingQueue;
|
|
9
|
+
private isProcessing;
|
|
10
|
+
private bufferQueue;
|
|
11
|
+
private bufferTimer;
|
|
12
|
+
private sessionQueue;
|
|
13
|
+
private sessionTimer;
|
|
14
|
+
private isProcessingSession;
|
|
8
15
|
constructor(ctx: Context, config: Config, logger: Logger);
|
|
9
16
|
logInfo(...args: any[]): void;
|
|
10
17
|
isProcessLinks(sessioncontent: string): Promise<false | {
|
|
@@ -16,11 +23,18 @@ export declare class BilibiliParser {
|
|
|
16
23
|
id: string;
|
|
17
24
|
}[]): Promise<string>;
|
|
18
25
|
isLinkProcessedRecently(ret: string, channelId: string): boolean;
|
|
26
|
+
queueSession(session: Session, sessioncontent: string): Promise<void>;
|
|
27
|
+
private flushSessionBuffer;
|
|
28
|
+
private processSessionQueue;
|
|
29
|
+
private processSessionTask;
|
|
19
30
|
processVideoFromLink(session: Session, ret: string, options?: {
|
|
20
31
|
video?: boolean;
|
|
21
32
|
audio?: boolean;
|
|
22
33
|
link?: boolean;
|
|
23
34
|
}): Promise<void>;
|
|
35
|
+
private flushBuffer;
|
|
36
|
+
private processQueue;
|
|
37
|
+
private processVideoTask;
|
|
24
38
|
private extractLastUrl;
|
|
25
39
|
convertBVToUrl(text: string): string[];
|
|
26
40
|
private numeral;
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "koishi-plugin-bilibili-videolink-analysis",
|
|
3
|
-
"description": "[<ruby>Bilibili视频解析<rp>(</rp><rt>点我查看食用方法</rt><rp>)</rp></ruby>](https://www.npmjs.com/package/koishi-plugin-bilibili-videolink-analysis)解析B站链接(支持小程序卡片)支持搜索点播功能!灵感来自完美的 [bili-parser](/market?keyword=bili-parser) !",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"version": "1.3.
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"typings": "lib/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"lib",
|
|
10
|
-
"src"
|
|
11
|
-
],
|
|
12
|
-
"homepage": "https://github.com/koishi-shangxue-plugins/koishi-shangxue-apps/tree/main/",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/koishi-shangxue-plugins/koishi-shangxue-apps/issues"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"chatbot",
|
|
18
|
-
"koishi",
|
|
19
|
-
"plugin",
|
|
20
|
-
"B站视频点播解析",
|
|
21
|
-
"bilibili-videolink-analysis"
|
|
22
|
-
],
|
|
23
|
-
"peerDependencies": {
|
|
24
|
-
"koishi": "^4.16.8"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-bilibili-videolink-analysis",
|
|
3
|
+
"description": "[<ruby>Bilibili视频解析<rp>(</rp><rt>点我查看食用方法</rt><rp>)</rp></ruby>](https://www.npmjs.com/package/koishi-plugin-bilibili-videolink-analysis)解析B站链接(支持小程序卡片)支持搜索点播功能!灵感来自完美的 [bili-parser](/market?keyword=bili-parser) !",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "1.3.3",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"typings": "lib/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib",
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/koishi-shangxue-plugins/koishi-shangxue-apps/tree/main/",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/koishi-shangxue-plugins/koishi-shangxue-apps/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"chatbot",
|
|
18
|
+
"koishi",
|
|
19
|
+
"plugin",
|
|
20
|
+
"B站视频点播解析",
|
|
21
|
+
"bilibili-videolink-analysis"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"koishi": "^4.16.8"
|
|
25
|
+
}
|
|
26
|
+
}
|