koishi-plugin-bilibili-videolink-analysis 1.1.18 → 1.1.20

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.
Files changed (2) hide show
  1. package/lib/index.js +96 -75
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -92,9 +92,12 @@ exports.Config = Schema.intersect([
92
92
  BVnumberParsing: Schema.boolean().default(true).description("是否允许根据`独立的BV、AV号`解析视频 `开启后,可以通过视频的BV、AV号解析视频。` <br> [触发说明见README](https://www.npmjs.com/package/koishi-plugin-bilibili-videolink-analysis)"),
93
93
  Maximumduration: Schema.number().default(25).description("允许解析的视频最大时长(分钟)`超过这个时长 就不会发视频`").min(1),
94
94
  Maximumduration_tip: Schema.union([
95
- Schema.const('不返回文字提示').description('不返回文字提示'),
96
- Schema.string().description('返回文字提示(请在右侧填写文字内容)').default('视频太长啦!还是去B站看吧~'),
97
- ]).description("对过长视频的文字提示内容").default('视频太长啦!还是去B站看吧~'),
95
+ Schema.const('return').description('不返回文字提示'),
96
+ Schema.object({
97
+ tipcontent: Schema.string().default('视频太长啦!内容还是去B站看吧~').description("文字提示内容"),
98
+ tipanalysis: Schema.boolean().default(false).description("是否进行图文解析(不会返回视频链接)"),
99
+ }).description('返回文字提示'),
100
+ ]).description("对`过长视频`的文字提示内容").default({}),
98
101
  MinimumTimeInterval: Schema.number().default(180).description("若干`秒`内 不再处理相同链接 `防止多bot互相触发 导致的刷屏/性能浪费`").min(1),
99
102
  }),
100
103
 
@@ -462,42 +465,12 @@ display: none !important;
462
465
  }
463
466
 
464
467
  let responseElements = []; // 用于存储所有要发送的元素
468
+ let shouldPerformTextParsing = config.linktextParsing; // 默认根据配置决定是否进行图文解析
469
+ //let videoTooLong = false; // 标记视频是否太长
465
470
 
466
- // 图文解析
467
- if (config.linktextParsing) {
468
- let fullText;
469
- if (config.bVideoShowLink) {
470
- fullText = ret; // 发送完整信息
471
- } else {
472
- // 去掉最后一个链接
473
- fullText = ret.replace(lastretUrl, '');
474
- }
475
-
476
- // 分割文本
477
- const textParts = fullText.split('${~~~}');
478
-
479
- // 循环处理每个分割后的部分
480
- for (const part of textParts) {
481
- const trimmedPart = part.trim(); // 去除首尾空格
482
- if (trimmedPart) { // 确保不是空字符串
483
- // 使用 h.parse 解析文本为消息元素
484
- const parsedElements = h.parse(trimmedPart);
485
-
486
- // 创建 message 元素
487
- const messageElement = h('message', {
488
- userId: session.userId,
489
- nickname: session.author?.nickname || session.username,
490
- }, parsedElements);
491
-
492
- // 添加 message 元素到 responseElements
493
- responseElements.push(messageElement);
494
- }
495
- }
496
- }
497
-
498
- // 视频/链接解析
471
+ // 视频/链接解析 - 先检查视频时长
499
472
  if (config.VideoParsing_ToLink) {
500
- const fullAPIurl = `https://api.xingzhige.com/API/b_parse/?url=${encodeURIComponent(lastretUrl)}`;
473
+ const fullAPIurl = `http://api.xingzhige.cn/API/b_parse/?url=${encodeURIComponent(lastretUrl)}`;
501
474
 
502
475
  try {
503
476
  const responseData = await ctx.http.get(fullAPIurl);
@@ -514,46 +487,59 @@ display: none !important;
514
487
  const videoDurationMinutes = videoDurationSeconds / 60;
515
488
 
516
489
  if (videoDurationMinutes > config.Maximumduration) {
517
- if (config.Maximumduration_tip !== '不返回文字提示') {
518
- await session.send(config.Maximumduration_tip);
519
- return;
520
- } else {
521
- return;
522
- }
523
- }
524
-
525
- const videoUrl = video.url;
490
+ //videoTooLong = true;
526
491
 
527
- logInfo(videoUrl);
528
- if (videoUrl) {
529
- if (options.link) {
530
- responseElements.push(h.text(videoUrl));
531
- } else if (options.audio) {
532
- responseElements.push(h.audio(videoUrl));
533
- } else {
534
- switch (config.VideoParsing_ToLink) {
535
- case '1':
536
- break;
537
- case '2':
538
- responseElements.push(h.video(videoUrl));
539
- break;
540
- case '3':
541
- responseElements.push(h.text(videoUrl));
542
- break;
543
- case '4':
544
- responseElements.push(h.text(videoUrl));
545
- responseElements.push(h.video(videoUrl));
546
- break;
547
- case '5':
548
- logger.info(videoUrl);
549
- responseElements.push(h.video(videoUrl));
550
- break;
551
- default:
552
- break;
492
+ // 根据 Maximumduration_tip 的值决定行为
493
+ if (config.Maximumduration_tip === 'return') {
494
+ // 不返回文字提示,直接返回
495
+ return;
496
+ } else if (typeof config.Maximumduration_tip === 'object') {
497
+ // 返回文字提示
498
+ if (config.Maximumduration_tip.tipcontent) {
499
+ if (config.Maximumduration_tip.tipanalysis) {
500
+ await responseElements.push(h.text(config.Maximumduration_tip.tipcontent))
501
+ } else {
502
+ await session.send(config.Maximumduration_tip.tipcontent);
503
+ }
553
504
  }
505
+ // 决定是否进行图文解析
506
+ shouldPerformTextParsing = config.Maximumduration_tip.tipanalysis === true;
554
507
  }
555
508
  } else {
556
- throw new Error("解析视频直链失败");
509
+ // 视频时长在允许范围内,处理视频
510
+ const videoUrl = video.url;
511
+ logInfo(videoUrl);
512
+
513
+ if (videoUrl) {
514
+ if (options.link) {
515
+ responseElements.push(h.text(videoUrl));
516
+ } else if (options.audio) {
517
+ responseElements.push(h.audio(videoUrl));
518
+ } else {
519
+ switch (config.VideoParsing_ToLink) {
520
+ case '1':
521
+ break;
522
+ case '2':
523
+ responseElements.push(h.video(videoUrl));
524
+ break;
525
+ case '3':
526
+ responseElements.push(h.text(videoUrl));
527
+ break;
528
+ case '4':
529
+ responseElements.push(h.text(videoUrl));
530
+ responseElements.push(h.video(videoUrl));
531
+ break;
532
+ case '5':
533
+ logger.info(videoUrl);
534
+ responseElements.push(h.video(videoUrl));
535
+ break;
536
+ default:
537
+ break;
538
+ }
539
+ }
540
+ } else {
541
+ throw new Error("解析视频直链失败");
542
+ }
557
543
  }
558
544
  } else {
559
545
  throw new Error("获取播放数据失败");
@@ -566,6 +552,43 @@ display: none !important;
566
552
  }
567
553
  }
568
554
 
555
+ // 图文解析 - 根据 shouldPerformTextParsing 决定是否执行
556
+ if (shouldPerformTextParsing) {
557
+ let fullText;
558
+ if (config.bVideoShowLink) {
559
+ fullText = ret; // 发送完整信息
560
+ } else {
561
+ // 去掉最后一个链接
562
+ fullText = ret.replace(lastretUrl, '');
563
+ }
564
+
565
+ // 分割文本
566
+ const textParts = fullText.split('${~~~}');
567
+
568
+ // 循环处理每个分割后的部分
569
+ for (const part of textParts) {
570
+ const trimmedPart = part.trim(); // 去除首尾空格
571
+ if (trimmedPart) { // 确保不是空字符串
572
+ // 使用 h.parse 解析文本为消息元素
573
+ const parsedElements = h.parse(trimmedPart);
574
+
575
+ // 创建 message 元素
576
+ const messageElement = h('message', {
577
+ userId: session.userId,
578
+ nickname: session.author?.nickname || session.username,
579
+ }, parsedElements);
580
+
581
+ // 添加 message 元素到 responseElements
582
+ responseElements.push(messageElement);
583
+ }
584
+ }
585
+ }
586
+
587
+ // 如果没有任何元素要发送,则直接返回
588
+ if (responseElements.length === 0) {
589
+ return;
590
+ }
591
+
569
592
  // 合并转发处理
570
593
  if (config.isfigure && (session.platform === "onebot" || session.platform === "red")) {
571
594
  logInfo(`使用合并转发,正在合并消息。`);
@@ -590,8 +613,6 @@ display: none !important;
590
613
  }
591
614
 
592
615
 
593
-
594
-
595
616
  // 提取最后一个URL
596
617
  function extractLastUrl(text) {
597
618
  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.18",
5
+ "version": "1.1.20",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [