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

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 +46 -12
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -118,6 +118,7 @@ exports.Config = Schema.intersect([
118
118
 
119
119
  Schema.object({
120
120
  isfigure: Schema.boolean().default(false).description("是否开启合并转发 `仅支持 onebot 适配器` 其他平台开启 无效").experimental(),
121
+ filebuffer: Schema.boolean().default(true).description("是否将视频链接下载后再发送 (以解决部分onebot协议端的问题)<br>否则使用视频直链发送").experimental(),
121
122
  middleware: Schema.boolean().default(false).description("前置中间件模式"),
122
123
  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"),
123
124
  }).description("调试设置"),
@@ -128,6 +129,7 @@ exports.Config = Schema.intersect([
128
129
  Schema.object({
129
130
  pageclose: Schema.boolean().default(true).description("自动`page.close()`<br>非开发者请勿改动").experimental(),
130
131
  loggerinfo: Schema.boolean().default(false).description("日志调试输出 `日常使用无需开启`<br>非开发者请勿改动").experimental(),
132
+ loggerinfofulljson: Schema.boolean().default(false).description("打印完整的机器人发送的json输出").experimental(),
131
133
  }).description("开发者选项"),
132
134
  ]);
133
135
 
@@ -545,31 +547,59 @@ display: none !important;
545
547
  }
546
548
  } else {
547
549
  // 视频时长在允许范围内,处理视频
548
- const videoUrl = video.url;
549
- logInfo(videoUrl);
550
+ let videoData = video.url; // 使用新变量名,避免覆盖原始URL
551
+ logInfo(videoData);
550
552
 
551
- if (videoUrl) {
553
+ if (config.filebuffer) {
554
+ try {
555
+ const videoFileBuffer = await ctx.http.file(video.url);
556
+ logInfo(videoFileBuffer);
557
+
558
+ // 检查文件类型
559
+ if (videoFileBuffer && videoFileBuffer.data) {
560
+ // 将ArrayBuffer转换为Buffer
561
+ const buffer = Buffer.from(videoFileBuffer.data);
562
+
563
+ // 获取MIME类型
564
+ const mimeType = videoFileBuffer.type || videoFileBuffer.mime || 'video/mp4';
565
+
566
+ // 创建data URI
567
+ const base64Data = buffer.toString('base64');
568
+ videoData = `data:${mimeType};base64,${base64Data}`;
569
+
570
+ logInfo("成功使用 ctx.http.file 将视频URL 转换为data URI格式");
571
+ } else {
572
+ logInfo("文件数据无效,使用原始URL");
573
+ }
574
+ } catch (error) {
575
+ logger.error("获取视频文件失败:", error);
576
+ // 出错时继续使用原始URL
577
+ }
578
+ }
579
+
580
+ if (videoData) {
552
581
  if (options.link) {
553
- videoElements.push(h.text(videoUrl));
582
+ // 如果是链接选项,仍然使用原始URL
583
+ videoElements.push(h.text(video.url));
554
584
  } else if (options.audio) {
555
- videoElements.push(h.audio(videoUrl));
585
+ videoElements.push(h.audio(videoData));
556
586
  } else {
557
587
  switch (config.VideoParsing_ToLink) {
558
588
  case '1':
559
589
  break;
560
590
  case '2':
561
- videoElements.push(h.video(videoUrl));
591
+ videoElements.push(h.video(videoData));
562
592
  break;
563
593
  case '3':
564
- videoElements.push(h.text(videoUrl));
594
+ videoElements.push(h.text(video.url));
565
595
  break;
566
596
  case '4':
567
- videoElements.push(h.text(videoUrl));
568
- videoElements.push(h.video(videoUrl));
597
+ videoElements.push(h.text(video.url));
598
+ videoElements.push(h.video(videoData));
569
599
  break;
570
600
  case '5':
571
- logger.info(videoUrl);
572
- videoElements.push(h.video(videoUrl));
601
+ logger.info(video.url);
602
+ videoElements.push(h.video(videoData));
573
603
  break;
574
604
  default:
575
605
  break;
@@ -578,6 +608,7 @@ display: none !important;
578
608
  } else {
579
609
  throw new Error("解析视频直链失败");
580
610
  }
611
+
581
612
  }
582
613
  } else {
583
614
  throw new Error("获取播放数据失败");
@@ -615,7 +646,10 @@ display: none !important;
615
646
  const figureContent = h('figure', {
616
647
  children: allElements
617
648
  });
618
- logInfo(JSON.stringify(figureContent, null, 2));
649
+
650
+ if (config.loggerinfofulljson) {
651
+ logInfo(JSON.stringify(figureContent, null, 2));
652
+ }
619
653
 
620
654
  // 发送合并转发消息
621
655
  await session.send(figureContent);
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.21",
5
+ "version": "1.1.23",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [