koishi-plugin-bilibili-videolink-analysis 1.1.12 → 1.1.14
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 +31 -126
- package/package.json +1 -1
- package/readme.md +5 -0
package/lib/index.js
CHANGED
|
@@ -53,7 +53,7 @@ exports.usage = `
|
|
|
53
53
|
|
|
54
54
|
exports.Config = Schema.intersect([
|
|
55
55
|
Schema.object({
|
|
56
|
-
demand: Schema.boolean().default(true).description("
|
|
56
|
+
demand: Schema.boolean().default(true).description("开启点播指令功能<br>`其实点播登录不登录 都搜不准,登录只是写着玩的`"),
|
|
57
57
|
timeout: Schema.number().role('slider').min(1).max(300).step(1).default(60).description('指定播放视频的输入时限。`单位 秒`'),
|
|
58
58
|
point: Schema.tuple([Number, Number]).description('序号标注位置。分别表示`距离顶部 距离左侧`的百分比').default([50, 50]),
|
|
59
59
|
enable: Schema.boolean().description('是否开启自动解析`选择对应视频 会自动解析视频内容`').default(true),
|
|
@@ -98,10 +98,14 @@ exports.Config = Schema.intersect([
|
|
|
98
98
|
|
|
99
99
|
Schema.object({
|
|
100
100
|
isfigure: Schema.boolean().default(false).description("是否开启合并转发 `仅支持 onebot 适配器` 其他平台开启 无效").experimental(),
|
|
101
|
-
userAgent: 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"),
|
|
102
101
|
middleware: Schema.boolean().default(false).description("前置中间件模式"),
|
|
103
|
-
|
|
102
|
+
userAgent: 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"),
|
|
104
103
|
}).description("调试设置"),
|
|
104
|
+
|
|
105
|
+
Schema.object({
|
|
106
|
+
pageclose: Schema.boolean().default(true).description("自动`page.close()`<br>非开发者请勿改动").experimental(),
|
|
107
|
+
loggerinfo: Schema.boolean().default(false).description("日志调试输出 `日常使用无需开启`<br>非开发者请勿改动").experimental(),
|
|
108
|
+
}).description("开发者选项"),
|
|
105
109
|
]);
|
|
106
110
|
|
|
107
111
|
function apply(ctx, config) {
|
|
@@ -316,7 +320,13 @@ display: none !important;
|
|
|
316
320
|
width: 1440,
|
|
317
321
|
height: viewportHeight
|
|
318
322
|
})
|
|
323
|
+
logInfo("窗口:宽度:")
|
|
324
|
+
logInfo(1440)
|
|
325
|
+
|
|
326
|
+
logInfo("窗口:高度:")
|
|
327
|
+
logInfo(viewportHeight)
|
|
319
328
|
let msg;
|
|
329
|
+
|
|
320
330
|
// 截图
|
|
321
331
|
const videoListElement = await page.$('.video-list.row')
|
|
322
332
|
if (videoListElement) {
|
|
@@ -325,8 +335,9 @@ display: none !important;
|
|
|
325
335
|
})
|
|
326
336
|
msg = h.image(imgBuf, 'image/png')
|
|
327
337
|
}
|
|
328
|
-
|
|
329
|
-
|
|
338
|
+
if (page && config.pageclose) {
|
|
339
|
+
await page.close()
|
|
340
|
+
}
|
|
330
341
|
|
|
331
342
|
// 发送截图
|
|
332
343
|
await session.send(msg)
|
|
@@ -360,111 +371,6 @@ display: none !important;
|
|
|
360
371
|
})
|
|
361
372
|
}
|
|
362
373
|
|
|
363
|
-
if (config.loggerinfo) {
|
|
364
|
-
ctx.command('B站点播/调试点播 [keyword]', '调试时点播B站视频')
|
|
365
|
-
.option('video', '-v 解析返回视频')
|
|
366
|
-
.option('audio', '-a 解析返回语音')
|
|
367
|
-
.option('link', '-l 解析返回链接')
|
|
368
|
-
.option('page', '-p <page:number> 指定页数', { fallback: '1' })
|
|
369
|
-
.example('调试点播 遠い空へ -v')
|
|
370
|
-
.action(async ({ options, session }, keyword) => {
|
|
371
|
-
if (!keyword) {
|
|
372
|
-
await session.execute('调试点播 -h');
|
|
373
|
-
return '没输入keyword';
|
|
374
|
-
}
|
|
375
|
-
const url = `https://search.bilibili.com/video?keyword=${encodeURIComponent(keyword)}&page=${options.page}&o=30`;
|
|
376
|
-
const page = await ctx.puppeteer.page();
|
|
377
|
-
await page.goto(url, {
|
|
378
|
-
waitUntil: 'networkidle2',
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
// 获取视频列表并为每个视频元素添加序号
|
|
382
|
-
const videos = await page.evaluate((point) => {
|
|
383
|
-
const items = Array.from(document.querySelectorAll('.video-list-item:not([style*="display: none"])'));
|
|
384
|
-
return items.map((item, index) => {
|
|
385
|
-
const link = item.querySelector('a');
|
|
386
|
-
const href = link?.getAttribute('href') || '';
|
|
387
|
-
const idMatch = href.match(/\/video\/(BV\w+)\//);
|
|
388
|
-
const id = idMatch ? idMatch[1] : '';
|
|
389
|
-
if (!id) {
|
|
390
|
-
const htmlElement = item;
|
|
391
|
-
htmlElement.style.display = 'none';
|
|
392
|
-
} else {
|
|
393
|
-
const overlay = document.createElement('div');
|
|
394
|
-
overlay.style.position = 'absolute';
|
|
395
|
-
overlay.style.top = `${point[0]}%`;
|
|
396
|
-
overlay.style.left = `${point[1]}%`;
|
|
397
|
-
overlay.style.transform = 'translate(-50%, -50%)';
|
|
398
|
-
overlay.style.fontSize = '48px';
|
|
399
|
-
overlay.style.fontWeight = 'bold';
|
|
400
|
-
overlay.style.color = 'black';
|
|
401
|
-
overlay.style.zIndex = '10';
|
|
402
|
-
overlay.style.backgroundColor = 'rgba(255, 255, 255, 0.7)';
|
|
403
|
-
overlay.style.padding = '10px';
|
|
404
|
-
overlay.style.borderRadius = '8px';
|
|
405
|
-
overlay.textContent = `${index + 1}`;
|
|
406
|
-
const videoElement = item;
|
|
407
|
-
videoElement.style.position = 'relative';
|
|
408
|
-
videoElement.appendChild(overlay);
|
|
409
|
-
}
|
|
410
|
-
return { id };
|
|
411
|
-
}).filter(video => video.id);
|
|
412
|
-
}, config.point);
|
|
413
|
-
|
|
414
|
-
// 如果开启了日志调试模式,打印获取到的视频信息
|
|
415
|
-
logInfo(options);
|
|
416
|
-
logInfo(`共找到 ${videos.length} 个视频:`);
|
|
417
|
-
videos.forEach((video, index) => {
|
|
418
|
-
logInfo(`序号 ${index + 1}: ID - ${video.id}`);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
if (videos.length === 0) {
|
|
422
|
-
await page.close();
|
|
423
|
-
return '未找到相关视频。';
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// 动态调整窗口大小以适应视频数量
|
|
427
|
-
const viewportHeight = 200 + videos.length * 100;
|
|
428
|
-
await page.setViewport({
|
|
429
|
-
width: 1440,
|
|
430
|
-
height: viewportHeight,
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
let msg;
|
|
434
|
-
// 截取整个页面
|
|
435
|
-
const imgBuf = await page.screenshot({ fullPage: true });
|
|
436
|
-
msg = h.image(imgBuf, 'image/png');
|
|
437
|
-
|
|
438
|
-
await page.close();
|
|
439
|
-
|
|
440
|
-
// 发送截图
|
|
441
|
-
await session.send(msg);
|
|
442
|
-
// 提示用户输入
|
|
443
|
-
await session.send(`请选择视频的序号:`);
|
|
444
|
-
// 等待用户输入
|
|
445
|
-
const userChoice = await session.prompt(config.timeout * 1000);
|
|
446
|
-
const choiceIndex = parseInt(userChoice) - 1;
|
|
447
|
-
if (isNaN(choiceIndex) || choiceIndex < 0 || choiceIndex >= videos.length) {
|
|
448
|
-
return '输入无效,请输入正确的序号。';
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// 返回用户选择的视频ID
|
|
452
|
-
const chosenVideo = videos[choiceIndex];
|
|
453
|
-
// 如果开启了日志调试模式,打印用户选择的视频信息
|
|
454
|
-
logInfo(`渲染序号设置\noverlay.style.top = ${config.point[0]}% \noverlay.style.left = ${config.point[1]}%`);
|
|
455
|
-
logInfo(`用户选择了序号 ${choiceIndex + 1}: ID - ${chosenVideo.id}`);
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if (config.enable) {
|
|
459
|
-
// 开启自动解析了
|
|
460
|
-
|
|
461
|
-
const ret = await extractLinks(session, config, ctx, [{ type: 'Video', id: chosenVideo.id }], logger);
|
|
462
|
-
if (ret && !isLinkProcessedRecently(ret, lastProcessedUrls, config, logger)) {
|
|
463
|
-
await processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
374
|
//判断是否需要解析
|
|
469
375
|
async function isProcessLinks(sessioncontent) {
|
|
470
376
|
// 解析内容中的链接
|
|
@@ -543,27 +449,23 @@ display: none !important;
|
|
|
543
449
|
// 分割文本
|
|
544
450
|
const textParts = fullText.split('${~~~}');
|
|
545
451
|
|
|
546
|
-
//
|
|
547
|
-
let messageContent = [];
|
|
548
|
-
|
|
549
|
-
// 将分割后的文本部分解析为消息元素,并添加到 messageContent
|
|
452
|
+
// 循环处理每个分割后的部分
|
|
550
453
|
for (const part of textParts) {
|
|
551
454
|
const trimmedPart = part.trim(); // 去除首尾空格
|
|
552
455
|
if (trimmedPart) { // 确保不是空字符串
|
|
553
456
|
// 使用 h.parse 解析文本为消息元素
|
|
554
457
|
const parsedElements = h.parse(trimmedPart);
|
|
555
|
-
messageContent.push(...parsedElements);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
458
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
459
|
+
// 创建 message 元素
|
|
460
|
+
const messageElement = h('message', {
|
|
461
|
+
userId: session.userId,
|
|
462
|
+
nickname: session.author?.nickname || session.username,
|
|
463
|
+
}, parsedElements);
|
|
564
464
|
|
|
565
|
-
|
|
566
|
-
|
|
465
|
+
// 添加 message 元素到 responseElements
|
|
466
|
+
responseElements.push(messageElement);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
567
469
|
}
|
|
568
470
|
|
|
569
471
|
// 视频/链接解析
|
|
@@ -577,7 +479,9 @@ display: none !important;
|
|
|
577
479
|
const { bvid, cid, video } = responseData.data;
|
|
578
480
|
const bilibiliUrl = `https://api.bilibili.com/x/player/playurl?fnval=80&cid=${cid}&bvid=${bvid}`;
|
|
579
481
|
const playData = await ctx.http.get(bilibiliUrl);
|
|
482
|
+
|
|
580
483
|
logInfo(bilibiliUrl);
|
|
484
|
+
|
|
581
485
|
if (playData.code === 0 && playData.data && playData.data.dash.duration) {
|
|
582
486
|
const videoDurationSeconds = playData.data.dash.duration;
|
|
583
487
|
const videoDurationMinutes = videoDurationSeconds / 60;
|
|
@@ -592,8 +496,8 @@ display: none !important;
|
|
|
592
496
|
}
|
|
593
497
|
|
|
594
498
|
const videoUrl = video.url;
|
|
595
|
-
logInfo(videoUrl);
|
|
596
499
|
|
|
500
|
+
logInfo(videoUrl);
|
|
597
501
|
if (videoUrl) {
|
|
598
502
|
if (options.link) {
|
|
599
503
|
responseElements.push(h.text(videoUrl));
|
|
@@ -654,12 +558,13 @@ display: none !important;
|
|
|
654
558
|
}
|
|
655
559
|
}
|
|
656
560
|
|
|
657
|
-
logInfo(
|
|
561
|
+
logInfo(`机器人已发送完整消息。`);
|
|
658
562
|
return;
|
|
659
563
|
}
|
|
660
564
|
|
|
661
565
|
|
|
662
566
|
|
|
567
|
+
|
|
663
568
|
// 提取最后一个URL
|
|
664
569
|
function extractLastUrl(text) {
|
|
665
570
|
const urlPattern = /https?:\/\/[^\s]+/g;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "koishi-plugin-bilibili-videolink-analysis",
|
|
3
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
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.14",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
8
8
|
"files": [
|
package/readme.md
CHANGED
|
@@ -178,9 +178,14 @@ https://www.bilibili.com/video/BV1ii421Q7oj
|
|
|
178
178
|
<details>
|
|
179
179
|
<summary>点击此处 可查看更新日志</summary>
|
|
180
180
|
|
|
181
|
+
- **1.1.14**
|
|
182
|
+
- 上次更新了什么?
|
|
183
|
+
- 新增page.close调试选项
|
|
184
|
+
|
|
181
185
|
- **1.1.12**
|
|
182
186
|
- 支持合并转发
|
|
183
187
|
- 支持独立的AV号
|
|
188
|
+
- 修复合并转发与`${~~~}`不兼容的问题
|
|
184
189
|
|
|
185
190
|
- **1.1.11**
|
|
186
191
|
- 又想写了(指readme)
|