koishi-plugin-bilibili-videolink-analysis 1.1.20 → 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 +63 -45
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -455,7 +455,6 @@ display: none !important;
455
455
  return false; // 没有处理过
456
456
  }
457
457
 
458
- //解析视频并返回
459
458
  async function processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options = { video: true }) {
460
459
  const lastretUrl = extractLastUrl(ret);
461
460
 
@@ -464,11 +463,44 @@ display: none !important;
464
463
  await session.send(config.waitTip_Switch);
465
464
  }
466
465
 
467
- let responseElements = []; // 用于存储所有要发送的元素
466
+ let videoElements = []; // 用于存储视频相关元素
467
+ let textElements = []; // 用于存储图文解析元素
468
468
  let shouldPerformTextParsing = config.linktextParsing; // 默认根据配置决定是否进行图文解析
469
- //let videoTooLong = false; // 标记视频是否太长
469
+ let isLongVideo = false; // 标记视频是否过长
470
470
 
471
- // 视频/链接解析 - 先检查视频时长
471
+ // 先进行图文解析
472
+ if (shouldPerformTextParsing) {
473
+ let fullText;
474
+ if (config.bVideoShowLink) {
475
+ fullText = ret; // 发送完整信息
476
+ } else {
477
+ // 去掉最后一个链接
478
+ fullText = ret.replace(lastretUrl, '');
479
+ }
480
+
481
+ // 分割文本
482
+ const textParts = fullText.split('${~~~}');
483
+
484
+ // 循环处理每个分割后的部分
485
+ for (const part of textParts) {
486
+ const trimmedPart = part.trim(); // 去除首尾空格
487
+ if (trimmedPart) { // 确保不是空字符串
488
+ // 使用 h.parse 解析文本为消息元素
489
+ const parsedElements = h.parse(trimmedPart);
490
+
491
+ // 创建 message 元素
492
+ const messageElement = h('message', {
493
+ userId: session.userId,
494
+ nickname: session.author?.nickname || session.username,
495
+ }, parsedElements);
496
+
497
+ // 添加 message 元素到 textElements
498
+ textElements.push(messageElement);
499
+ }
500
+ }
501
+ }
502
+
503
+ // 视频/链接解析
472
504
  if (config.VideoParsing_ToLink) {
473
505
  const fullAPIurl = `http://api.xingzhige.cn/API/b_parse/?url=${encodeURIComponent(lastretUrl)}`;
474
506
 
@@ -487,7 +519,7 @@ display: none !important;
487
519
  const videoDurationMinutes = videoDurationSeconds / 60;
488
520
 
489
521
  if (videoDurationMinutes > config.Maximumduration) {
490
- //videoTooLong = true;
522
+ isLongVideo = true;
491
523
 
492
524
  // 根据 Maximumduration_tip 的值决定行为
493
525
  if (config.Maximumduration_tip === 'return') {
@@ -497,13 +529,19 @@ display: none !important;
497
529
  // 返回文字提示
498
530
  if (config.Maximumduration_tip.tipcontent) {
499
531
  if (config.Maximumduration_tip.tipanalysis) {
500
- await responseElements.push(h.text(config.Maximumduration_tip.tipcontent))
532
+ videoElements.push(h.text(config.Maximumduration_tip.tipcontent));
501
533
  } else {
502
534
  await session.send(config.Maximumduration_tip.tipcontent);
503
535
  }
504
536
  }
537
+
505
538
  // 决定是否进行图文解析
506
539
  shouldPerformTextParsing = config.Maximumduration_tip.tipanalysis === true;
540
+
541
+ // 如果不进行图文解析,清空已准备的文本元素
542
+ if (!shouldPerformTextParsing) {
543
+ textElements = [];
544
+ }
507
545
  }
508
546
  } else {
509
547
  // 视频时长在允许范围内,处理视频
@@ -512,26 +550,26 @@ display: none !important;
512
550
 
513
551
  if (videoUrl) {
514
552
  if (options.link) {
515
- responseElements.push(h.text(videoUrl));
553
+ videoElements.push(h.text(videoUrl));
516
554
  } else if (options.audio) {
517
- responseElements.push(h.audio(videoUrl));
555
+ videoElements.push(h.audio(videoUrl));
518
556
  } else {
519
557
  switch (config.VideoParsing_ToLink) {
520
558
  case '1':
521
559
  break;
522
560
  case '2':
523
- responseElements.push(h.video(videoUrl));
561
+ videoElements.push(h.video(videoUrl));
524
562
  break;
525
563
  case '3':
526
- responseElements.push(h.text(videoUrl));
564
+ videoElements.push(h.text(videoUrl));
527
565
  break;
528
566
  case '4':
529
- responseElements.push(h.text(videoUrl));
530
- responseElements.push(h.video(videoUrl));
567
+ videoElements.push(h.text(videoUrl));
568
+ videoElements.push(h.video(videoUrl));
531
569
  break;
532
570
  case '5':
533
571
  logger.info(videoUrl);
534
- responseElements.push(h.video(videoUrl));
572
+ videoElements.push(h.video(videoUrl));
535
573
  break;
536
574
  default:
537
575
  break;
@@ -552,40 +590,20 @@ display: none !important;
552
590
  }
553
591
  }
554
592
 
555
- // 图文解析 - 根据 shouldPerformTextParsing 决定是否执行
556
- if (shouldPerformTextParsing) {
557
- let fullText;
558
- if (config.bVideoShowLink) {
559
- fullText = ret; // 发送完整信息
560
- } else {
561
- // 去掉最后一个链接
562
- fullText = ret.replace(lastretUrl, '');
563
- }
593
+ // 准备发送的所有元素
594
+ let allElements = [];
564
595
 
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
- }
596
+ // 根据视频是否过长决定发送顺序
597
+ if (isLongVideo) {
598
+ // 过长视频:先发送过长提示(已在上面处理),然后是图文解析(如果启用)
599
+ allElements = [...textElements, ...videoElements];
600
+ } else {
601
+ // 正常视频:先发送图文解析,然后是视频元素
602
+ allElements = [...textElements, ...videoElements];
585
603
  }
586
604
 
587
605
  // 如果没有任何元素要发送,则直接返回
588
- if (responseElements.length === 0) {
606
+ if (allElements.length === 0) {
589
607
  return;
590
608
  }
591
609
 
@@ -595,7 +613,7 @@ display: none !important;
595
613
 
596
614
  // 创建 figure 元素
597
615
  const figureContent = h('figure', {
598
- children: responseElements // 直接使用 responseElements
616
+ children: allElements
599
617
  });
600
618
  logInfo(JSON.stringify(figureContent, null, 2));
601
619
 
@@ -603,7 +621,7 @@ display: none !important;
603
621
  await session.send(figureContent);
604
622
  } else {
605
623
  // 没有启用合并转发,按顺序发送所有元素
606
- for (const element of responseElements) {
624
+ for (const element of allElements) {
607
625
  await session.send(element);
608
626
  }
609
627
  }
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.20",
5
+ "version": "1.1.21",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [