koishi-plugin-bilibili-videolink-analysis 1.1.6 → 1.1.8

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 +43 -33
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -94,12 +94,14 @@ exports.Config = Schema.intersect([
94
94
  Schema.const("bv").description("BV 号"),
95
95
  Schema.const("av").description("AV 号"),
96
96
  ]).default("bv").description("ID 偏好").hidden(),
97
- bVideoImage: Schema.boolean().default(true).description("显示封面"),
98
- bVideoOwner: Schema.boolean().default(true).description("显示 UP 主"),
99
- bVideoDesc: Schema.boolean().default(false).description("显示简介`有的简介真的很长`"),
100
- bVideoStat: Schema.boolean().default(true).description("显示状态(*三连数据*)"),
101
- bVideoExtraStat: Schema.boolean().default(true).description("显示额外状态(*弹幕&观看*)"),
102
- bVideoShowLink: Schema.boolean().default(false).description("显示视频链接`开启可能会导致其他bot循环解析`"),
97
+ //bVideoImage: Schema.boolean().default(true).description("显示封面"),
98
+ //bVideoOwner: Schema.boolean().default(true).description("显示 UP 主"),
99
+ //bVideoDesc: Schema.boolean().default(false).description("显示简介`有的简介真的很长`"),
100
+ //bVideoStat: Schema.boolean().default(true).description("显示状态(*三连数据*)"),
101
+ //bVideoExtraStat: Schema.boolean().default(true).description("显示额外状态(*弹幕&观看*)"),
102
+ bVideo_area: Schema.string().role('textarea', { rows: [8, 16] }).description("图文解析的返回格式<br>注意变量格式,以及变量名称<br>比如 `${标题}` 不可以变成`${标题123}`,你可以直接删掉但是不能修改变量名称哦<br>当然变量也不能无中生有,下面的默认值内容 就是所有变量了,你仅可以删去变量 或者修改变量之外的格式。")
103
+ .default("${标题} --- ${UP主}\n---\n${封面}\n---\n${简介}\n---\n${点赞} --- ${投币}\n${收藏} --- ${转发}\n${观看} --- ${弹幕}"),
104
+ bVideoShowLink: Schema.boolean().default(false).description("在末尾显示视频的链接地址 `开启可能会导致其他bot循环解析`"),
103
105
  }).description("链接的图文解析设置"),
104
106
 
105
107
  Schema.object({
@@ -347,8 +349,8 @@ display: none !important;
347
349
  }
348
350
 
349
351
  if (config.enable) { // 开启自动解析了
350
- session.content = `https://www.bilibili.com/video/${chosenVideo.id}`
351
- const ret = await extractLinks(session, config, ctx, lastProcessedUrls, logger); // 提取链接
352
+
353
+ const ret = await extractLinks(session, config, ctx, [{ type: 'Video', id: chosenVideo.id }], logger); // 提取链接
352
354
  if (ret && !isLinkProcessedRecently(ret, lastProcessedUrls, config, logger)) {
353
355
  await processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options); // 解析视频并返回
354
356
  }
@@ -454,8 +456,8 @@ display: none !important;
454
456
 
455
457
  if (config.enable) {
456
458
  // 开启自动解析了
457
- session.content = `https://www.bilibili.com/video/${chosenVideo.id}`;
458
- const ret = await extractLinks(session, config, ctx, lastProcessedUrls, logger);
459
+
460
+ const ret = await extractLinks(session, config, ctx, [{ type: 'Video', id: chosenVideo.id }], logger);
459
461
  if (ret && !isLinkProcessedRecently(ret, lastProcessedUrls, config, logger)) {
460
462
  await processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options);
461
463
  }
@@ -727,43 +729,51 @@ display: none !important;
727
729
  return ret;
728
730
  }
729
731
  /**
730
- * 生成视频信息
731
- * @param id 视频 ID
732
- * @returns 文字视频信息
733
- */
732
+ * 生成视频信息
733
+ * @param id 视频 ID
734
+ * @returns 文字视频信息
735
+ */
734
736
  async gen_context(id) {
735
737
  const info = await this.fetch_video_info(id);
736
738
  if (!info || !info["data"])
737
739
  return null;
738
- var ret = `${info["data"]["title"]}\n`;
739
- this.config.bVideoImage
740
- ? (ret += `<img src=\"${info["data"]["pic"]}\"/>\n`)
741
- : null;
742
- this.config.bVideoOwner
743
- ? (ret += `UP主: ${info["data"]["owner"]["name"]}\n`)
744
- : null;
745
- this.config.bVideoDesc ? (ret += `${info["data"]["desc"]}\n`) : null;
746
- this.config.bVideoStat
747
- ? (ret += `点赞:${(0, numeral)(info["data"]["stat"]["like"], this.config)}\t\t投币:${(0, numeral)(info["data"]["stat"]["coin"], this.config)}\n`)
748
- : null;
749
- this.config.bVideoStat
750
- ? (ret += `收藏:${(0, numeral)(info["data"]["stat"]["favorite"], this.config)}\t\t转发:${(0, numeral)(info["data"]["stat"]["share"], this.config)}\n`)
751
- : null;
752
- this.config.bVideoExtraStat
753
- ? (ret += `观看:${(0, numeral)(info["data"]["stat"]["view"], this.config)}\t\t弹幕:${(0, numeral)(info["data"]["stat"]["danmaku"], this.config)}\n`)
754
- : null;
740
+
741
+ // 定义占位符对应的数据
742
+ const placeholders = {
743
+ '${标题}': info["data"]["title"],
744
+ '${UP主}': info["data"]["owner"]["name"],
745
+ '${封面}': `<img src="${info["data"]["pic"]}"/>`,
746
+ '${简介}': info["data"]["desc"],
747
+ '${点赞}': `点赞:${(0, numeral)(info["data"]["stat"]["like"], this.config)}`,
748
+ '${投币}': `投币:${(0, numeral)(info["data"]["stat"]["coin"], this.config)}`,
749
+ '${收藏}': `收藏:${(0, numeral)(info["data"]["stat"]["favorite"], this.config)}`,
750
+ '${转发}': `转发:${(0, numeral)(info["data"]["stat"]["share"], this.config)}`,
751
+ '${观看}': `观看:${(0, numeral)(info["data"]["stat"]["view"], this.config)}`,
752
+ '${弹幕}': `弹幕:${(0, numeral)(info["data"]["stat"]["danmaku"], this.config)}`,
753
+ };
754
+
755
+ // 根据配置项中的格式替换占位符
756
+ let ret = this.config.bVideo_area;
757
+ for (const [placeholder, value] of Object.entries(placeholders)) {
758
+ ret = ret.replace(new RegExp(placeholder.replace(/\$/g, '\\$'), 'g'), value);
759
+ }
760
+
761
+ // 根据 ID 偏好添加视频链接
755
762
  switch (this.config.bVideoIDPreference) {
756
763
  case "bv":
757
- ret += `https://www.bilibili.com/video/${info["data"]["bvid"]}\n`;
764
+ ret += `\nhttps://www.bilibili.com/video/${info["data"]["bvid"]}`;
758
765
  break;
759
766
  case "av":
760
- ret += `https://www.bilibili.com/video/av${info["data"]["aid"]}\n`;
767
+ ret += `\nhttps://www.bilibili.com/video/av${info["data"]["aid"]}`;
761
768
  break;
762
769
  default:
763
770
  break;
764
771
  }
772
+
765
773
  return ret;
766
774
  }
775
+
776
+
767
777
  }
768
778
 
769
779
  /**
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.6",
5
+ "version": "1.1.8",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [