koishi-plugin-bilibili-videolink-analysis 1.1.11 → 1.1.13
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 +89 -53
- package/package.json +1 -1
- package/readme.md +5 -1
package/lib/index.js
CHANGED
|
@@ -97,6 +97,7 @@ exports.Config = Schema.intersect([
|
|
|
97
97
|
}).description("链接的图文解析设置"),
|
|
98
98
|
|
|
99
99
|
Schema.object({
|
|
100
|
+
isfigure: Schema.boolean().default(false).description("是否开启合并转发 `仅支持 onebot 适配器` 其他平台开启 无效").experimental(),
|
|
100
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"),
|
|
101
102
|
middleware: Schema.boolean().default(false).description("前置中间件模式"),
|
|
102
103
|
loggerinfo: Schema.boolean().default(false).description("日志调试输出 `日常使用无需开启`"),
|
|
@@ -105,6 +106,16 @@ exports.Config = Schema.intersect([
|
|
|
105
106
|
|
|
106
107
|
function apply(ctx, config) {
|
|
107
108
|
|
|
109
|
+
function logInfo(message, message2) {
|
|
110
|
+
if (config.loggerinfo) {
|
|
111
|
+
if (message2) {
|
|
112
|
+
ctx.logger.info(message, message2)
|
|
113
|
+
} else {
|
|
114
|
+
ctx.logger.info(message);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
108
119
|
ctx.middleware(async (session, next) => {
|
|
109
120
|
let sessioncontent = session.content;
|
|
110
121
|
// 如果允许解析 BV 号,则进行解析
|
|
@@ -285,13 +296,13 @@ display: none !important;
|
|
|
285
296
|
}, config.point) // 传递配置的 point 参数
|
|
286
297
|
|
|
287
298
|
// 如果开启了日志调试模式,打印获取到的视频信息
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
299
|
+
|
|
300
|
+
logInfo(options)
|
|
301
|
+
logInfo(`共找到 ${videos.length} 个视频:`)
|
|
302
|
+
videos.forEach((video, index) => {
|
|
303
|
+
logInfo(`序号 ${index + 1}: ID - ${video.id}`)
|
|
304
|
+
})
|
|
305
|
+
|
|
295
306
|
|
|
296
307
|
if (videos.length === 0) {
|
|
297
308
|
await page.close()
|
|
@@ -335,10 +346,9 @@ display: none !important;
|
|
|
335
346
|
const chosenVideo = videos[choiceIndex]
|
|
336
347
|
|
|
337
348
|
// 如果开启了日志调试模式,打印用户选择的视频信息
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
349
|
+
logInfo(`渲染序号设置\noverlay.style.top = ${config.point[0]}% \noverlay.style.left = ${config.point[1]}%`)
|
|
350
|
+
logInfo(`用户选择了序号 ${choiceIndex + 1}: ID - ${chosenVideo.id}`)
|
|
351
|
+
|
|
342
352
|
|
|
343
353
|
if (config.enable) { // 开启自动解析了
|
|
344
354
|
|
|
@@ -401,14 +411,13 @@ display: none !important;
|
|
|
401
411
|
}).filter(video => video.id);
|
|
402
412
|
}, config.point);
|
|
403
413
|
|
|
404
|
-
// 如果开启了日志调试模式,打印获取到的视频信息
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
414
|
+
// 如果开启了日志调试模式,打印获取到的视频信息
|
|
415
|
+
logInfo(options);
|
|
416
|
+
logInfo(`共找到 ${videos.length} 个视频:`);
|
|
417
|
+
videos.forEach((video, index) => {
|
|
418
|
+
logInfo(`序号 ${index + 1}: ID - ${video.id}`);
|
|
419
|
+
});
|
|
420
|
+
|
|
412
421
|
if (videos.length === 0) {
|
|
413
422
|
await page.close();
|
|
414
423
|
return '未找到相关视频。';
|
|
@@ -442,10 +451,9 @@ display: none !important;
|
|
|
442
451
|
// 返回用户选择的视频ID
|
|
443
452
|
const chosenVideo = videos[choiceIndex];
|
|
444
453
|
// 如果开启了日志调试模式,打印用户选择的视频信息
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
454
|
+
logInfo(`渲染序号设置\noverlay.style.top = ${config.point[0]}% \noverlay.style.left = ${config.point[1]}%`);
|
|
455
|
+
logInfo(`用户选择了序号 ${choiceIndex + 1}: ID - ${chosenVideo.id}`);
|
|
456
|
+
|
|
449
457
|
|
|
450
458
|
if (config.enable) {
|
|
451
459
|
// 开启自动解析了
|
|
@@ -501,9 +509,8 @@ display: none !important;
|
|
|
501
509
|
const currentTime = Date.now();
|
|
502
510
|
|
|
503
511
|
if (lastProcessedUrls[lastretUrl] && (currentTime - lastProcessedUrls[lastretUrl] < config.MinimumTimeInterval * 1000)) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
512
|
+
ctx.logger.info(`重复出现,略过处理:\n ${lastretUrl}`);
|
|
513
|
+
|
|
507
514
|
return true; // 已经处理过
|
|
508
515
|
}
|
|
509
516
|
|
|
@@ -512,16 +519,18 @@ display: none !important;
|
|
|
512
519
|
return false; // 没有处理过
|
|
513
520
|
}
|
|
514
521
|
|
|
515
|
-
//解析视频并返回
|
|
522
|
+
//解析视频并返回
|
|
516
523
|
async function processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options = { video: true }) {
|
|
517
524
|
const lastretUrl = extractLastUrl(ret);
|
|
518
525
|
|
|
526
|
+
// 等待提示语单独发送
|
|
519
527
|
if (config.waitTip_Switch) {
|
|
520
|
-
// 等候的提示文字
|
|
521
528
|
await session.send(config.waitTip_Switch);
|
|
522
529
|
}
|
|
523
530
|
|
|
524
|
-
let
|
|
531
|
+
let responseElements = []; // 用于存储所有要发送的元素
|
|
532
|
+
|
|
533
|
+
// 图文解析
|
|
525
534
|
if (config.linktextParsing) {
|
|
526
535
|
let fullText;
|
|
527
536
|
if (config.bVideoShowLink) {
|
|
@@ -532,16 +541,28 @@ display: none !important;
|
|
|
532
541
|
}
|
|
533
542
|
|
|
534
543
|
// 分割文本
|
|
535
|
-
textParts = fullText.split('${~~~}');
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
544
|
+
const textParts = fullText.split('${~~~}');
|
|
545
|
+
|
|
546
|
+
// 循环处理每个分割后的部分
|
|
547
|
+
for (const part of textParts) {
|
|
548
|
+
const trimmedPart = part.trim(); // 去除首尾空格
|
|
549
|
+
if (trimmedPart) { // 确保不是空字符串
|
|
550
|
+
// 使用 h.parse 解析文本为消息元素
|
|
551
|
+
const parsedElements = h.parse(trimmedPart);
|
|
552
|
+
|
|
553
|
+
// 创建 message 元素
|
|
554
|
+
const messageElement = h('message', {
|
|
555
|
+
userId: session.userId,
|
|
556
|
+
nickname: session.author?.nickname || session.username,
|
|
557
|
+
}, parsedElements);
|
|
558
|
+
|
|
559
|
+
// 添加 message 元素到 responseElements
|
|
560
|
+
responseElements.push(messageElement);
|
|
561
|
+
}
|
|
542
562
|
}
|
|
543
563
|
}
|
|
544
564
|
|
|
565
|
+
// 视频/链接解析
|
|
545
566
|
if (config.VideoParsing_ToLink) {
|
|
546
567
|
const fullAPIurl = `https://api.xingzhige.com/API/b_parse/?url=${encodeURIComponent(lastretUrl)}`;
|
|
547
568
|
|
|
@@ -552,9 +573,9 @@ display: none !important;
|
|
|
552
573
|
const { bvid, cid, video } = responseData.data;
|
|
553
574
|
const bilibiliUrl = `https://api.bilibili.com/x/player/playurl?fnval=80&cid=${cid}&bvid=${bvid}`;
|
|
554
575
|
const playData = await ctx.http.get(bilibiliUrl);
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
576
|
+
|
|
577
|
+
logInfo(bilibiliUrl);
|
|
578
|
+
|
|
558
579
|
if (playData.code === 0 && playData.data && playData.data.dash.duration) {
|
|
559
580
|
const videoDurationSeconds = playData.data.dash.duration;
|
|
560
581
|
const videoDurationMinutes = videoDurationSeconds / 60;
|
|
@@ -569,33 +590,30 @@ display: none !important;
|
|
|
569
590
|
}
|
|
570
591
|
|
|
571
592
|
const videoUrl = video.url;
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
593
|
+
|
|
594
|
+
logInfo(videoUrl);
|
|
575
595
|
if (videoUrl) {
|
|
576
596
|
if (options.link) {
|
|
577
|
-
|
|
578
|
-
return;
|
|
597
|
+
responseElements.push(h.text(videoUrl));
|
|
579
598
|
} else if (options.audio) {
|
|
580
|
-
|
|
581
|
-
return;
|
|
599
|
+
responseElements.push(h.audio(videoUrl));
|
|
582
600
|
} else {
|
|
583
601
|
switch (config.VideoParsing_ToLink) {
|
|
584
602
|
case '1':
|
|
585
603
|
break;
|
|
586
604
|
case '2':
|
|
587
|
-
|
|
605
|
+
responseElements.push(h.video(videoUrl));
|
|
588
606
|
break;
|
|
589
607
|
case '3':
|
|
590
|
-
|
|
608
|
+
responseElements.push(h.text(videoUrl));
|
|
591
609
|
break;
|
|
592
610
|
case '4':
|
|
593
|
-
|
|
594
|
-
|
|
611
|
+
responseElements.push(h.text(videoUrl));
|
|
612
|
+
responseElements.push(h.video(videoUrl));
|
|
595
613
|
break;
|
|
596
614
|
case '5':
|
|
597
615
|
logger.info(videoUrl);
|
|
598
|
-
|
|
616
|
+
responseElements.push(h.video(videoUrl));
|
|
599
617
|
break;
|
|
600
618
|
default:
|
|
601
619
|
break;
|
|
@@ -615,14 +633,32 @@ display: none !important;
|
|
|
615
633
|
}
|
|
616
634
|
}
|
|
617
635
|
|
|
618
|
-
|
|
619
|
-
|
|
636
|
+
// 合并转发处理
|
|
637
|
+
if (config.isfigure && (session.platform === "onebot" || session.platform === "red")) {
|
|
638
|
+
logInfo(`使用合并转发,正在合并消息。`);
|
|
639
|
+
|
|
640
|
+
// 创建 figure 元素
|
|
641
|
+
const figureContent = h('figure', {
|
|
642
|
+
children: responseElements // 直接使用 responseElements
|
|
643
|
+
});
|
|
644
|
+
logInfo(JSON.stringify(figureContent, null, 2));
|
|
645
|
+
|
|
646
|
+
// 发送合并转发消息
|
|
647
|
+
await session.send(figureContent);
|
|
648
|
+
} else {
|
|
649
|
+
// 没有启用合并转发,按顺序发送所有元素
|
|
650
|
+
for (const element of responseElements) {
|
|
651
|
+
await session.send(element);
|
|
652
|
+
}
|
|
620
653
|
}
|
|
654
|
+
|
|
655
|
+
logInfo(`机器人已发送完整消息。`);
|
|
621
656
|
return;
|
|
622
657
|
}
|
|
623
658
|
|
|
624
659
|
|
|
625
660
|
|
|
661
|
+
|
|
626
662
|
// 提取最后一个URL
|
|
627
663
|
function extractLastUrl(text) {
|
|
628
664
|
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.13",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
8
8
|
"files": [
|
package/readme.md
CHANGED
|
@@ -178,11 +178,15 @@ https://www.bilibili.com/video/BV1ii421Q7oj
|
|
|
178
178
|
<details>
|
|
179
179
|
<summary>点击此处 可查看更新日志</summary>
|
|
180
180
|
|
|
181
|
+
- **1.1.12**
|
|
182
|
+
- 支持合并转发
|
|
183
|
+
- 支持独立的AV号
|
|
184
|
+
- 修复合并转发与`${~~~}`不兼容的问题
|
|
185
|
+
|
|
181
186
|
- **1.1.11**
|
|
182
187
|
- 又想写了(指readme)
|
|
183
188
|
- 新增解析格式的的变量分割线
|
|
184
189
|
- 期间还写了什么,忘了
|
|
185
|
-
- 支持独立的AV号
|
|
186
190
|
|
|
187
191
|
- **1.0.0**
|
|
188
192
|
- 不想写了
|