koishi-plugin-bilibili-videolink-analysis 1.1.19 → 1.1.21

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 +86 -47
  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
 
@@ -452,7 +455,6 @@ display: none !important;
452
455
  return false; // 没有处理过
453
456
  }
454
457
 
455
- //解析视频并返回
456
458
  async function processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options = { video: true }) {
457
459
  const lastretUrl = extractLastUrl(ret);
458
460
 
@@ -461,10 +463,13 @@ display: none !important;
461
463
  await session.send(config.waitTip_Switch);
462
464
  }
463
465
 
464
- let responseElements = []; // 用于存储所有要发送的元素
466
+ let videoElements = []; // 用于存储视频相关元素
467
+ let textElements = []; // 用于存储图文解析元素
468
+ let shouldPerformTextParsing = config.linktextParsing; // 默认根据配置决定是否进行图文解析
469
+ let isLongVideo = false; // 标记视频是否过长
465
470
 
466
- // 图文解析
467
- if (config.linktextParsing) {
471
+ // 先进行图文解析
472
+ if (shouldPerformTextParsing) {
468
473
  let fullText;
469
474
  if (config.bVideoShowLink) {
470
475
  fullText = ret; // 发送完整信息
@@ -489,8 +494,8 @@ display: none !important;
489
494
  nickname: session.author?.nickname || session.username,
490
495
  }, parsedElements);
491
496
 
492
- // 添加 message 元素到 responseElements
493
- responseElements.push(messageElement);
497
+ // 添加 message 元素到 textElements
498
+ textElements.push(messageElement);
494
499
  }
495
500
  }
496
501
  }
@@ -514,46 +519,65 @@ display: none !important;
514
519
  const videoDurationMinutes = videoDurationSeconds / 60;
515
520
 
516
521
  if (videoDurationMinutes > config.Maximumduration) {
517
- if (config.Maximumduration_tip !== '不返回文字提示') {
518
- await session.send(config.Maximumduration_tip);
519
- return;
520
- } else {
522
+ isLongVideo = true;
523
+
524
+ // 根据 Maximumduration_tip 的值决定行为
525
+ if (config.Maximumduration_tip === 'return') {
526
+ // 不返回文字提示,直接返回
521
527
  return;
522
- }
523
- }
528
+ } else if (typeof config.Maximumduration_tip === 'object') {
529
+ // 返回文字提示
530
+ if (config.Maximumduration_tip.tipcontent) {
531
+ if (config.Maximumduration_tip.tipanalysis) {
532
+ videoElements.push(h.text(config.Maximumduration_tip.tipcontent));
533
+ } else {
534
+ await session.send(config.Maximumduration_tip.tipcontent);
535
+ }
536
+ }
524
537
 
525
- const videoUrl = video.url;
538
+ // 决定是否进行图文解析
539
+ shouldPerformTextParsing = config.Maximumduration_tip.tipanalysis === true;
526
540
 
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;
541
+ // 如果不进行图文解析,清空已准备的文本元素
542
+ if (!shouldPerformTextParsing) {
543
+ textElements = [];
553
544
  }
554
545
  }
555
546
  } else {
556
- throw new Error("解析视频直链失败");
547
+ // 视频时长在允许范围内,处理视频
548
+ const videoUrl = video.url;
549
+ logInfo(videoUrl);
550
+
551
+ if (videoUrl) {
552
+ if (options.link) {
553
+ videoElements.push(h.text(videoUrl));
554
+ } else if (options.audio) {
555
+ videoElements.push(h.audio(videoUrl));
556
+ } else {
557
+ switch (config.VideoParsing_ToLink) {
558
+ case '1':
559
+ break;
560
+ case '2':
561
+ videoElements.push(h.video(videoUrl));
562
+ break;
563
+ case '3':
564
+ videoElements.push(h.text(videoUrl));
565
+ break;
566
+ case '4':
567
+ videoElements.push(h.text(videoUrl));
568
+ videoElements.push(h.video(videoUrl));
569
+ break;
570
+ case '5':
571
+ logger.info(videoUrl);
572
+ videoElements.push(h.video(videoUrl));
573
+ break;
574
+ default:
575
+ break;
576
+ }
577
+ }
578
+ } else {
579
+ throw new Error("解析视频直链失败");
580
+ }
557
581
  }
558
582
  } else {
559
583
  throw new Error("获取播放数据失败");
@@ -566,13 +590,30 @@ display: none !important;
566
590
  }
567
591
  }
568
592
 
593
+ // 准备发送的所有元素
594
+ let allElements = [];
595
+
596
+ // 根据视频是否过长决定发送顺序
597
+ if (isLongVideo) {
598
+ // 过长视频:先发送过长提示(已在上面处理),然后是图文解析(如果启用)
599
+ allElements = [...textElements, ...videoElements];
600
+ } else {
601
+ // 正常视频:先发送图文解析,然后是视频元素
602
+ allElements = [...textElements, ...videoElements];
603
+ }
604
+
605
+ // 如果没有任何元素要发送,则直接返回
606
+ if (allElements.length === 0) {
607
+ return;
608
+ }
609
+
569
610
  // 合并转发处理
570
611
  if (config.isfigure && (session.platform === "onebot" || session.platform === "red")) {
571
612
  logInfo(`使用合并转发,正在合并消息。`);
572
613
 
573
614
  // 创建 figure 元素
574
615
  const figureContent = h('figure', {
575
- children: responseElements // 直接使用 responseElements
616
+ children: allElements
576
617
  });
577
618
  logInfo(JSON.stringify(figureContent, null, 2));
578
619
 
@@ -580,7 +621,7 @@ display: none !important;
580
621
  await session.send(figureContent);
581
622
  } else {
582
623
  // 没有启用合并转发,按顺序发送所有元素
583
- for (const element of responseElements) {
624
+ for (const element of allElements) {
584
625
  await session.send(element);
585
626
  }
586
627
  }
@@ -590,8 +631,6 @@ display: none !important;
590
631
  }
591
632
 
592
633
 
593
-
594
-
595
634
  // 提取最后一个URL
596
635
  function extractLastUrl(text) {
597
636
  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.19",
5
+ "version": "1.1.21",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [