koishi-plugin-bilibili-videolink-analysis 1.1.13 → 1.1.15

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 (3) hide show
  1. package/lib/index.js +19 -111
  2. package/package.json +1 -1
  3. package/readme.md +4 -0
package/lib/index.js CHANGED
@@ -53,7 +53,7 @@ exports.usage = `
53
53
 
54
54
  exports.Config = Schema.intersect([
55
55
  Schema.object({
56
- demand: Schema.boolean().default(true).description("开启点播指令功能"),
56
+ demand: Schema.boolean().default(true).description("开启点播指令功能<br>`其实点播登录不登录 都搜不准,登录只是写着玩的`"),
57
57
  timeout: Schema.number().role('slider').min(1).max(300).step(1).default(60).description('指定播放视频的输入时限。`单位 秒`'),
58
58
  point: Schema.tuple([Number, Number]).description('序号标注位置。分别表示`距离顶部 距离左侧`的百分比').default([50, 50]),
59
59
  enable: Schema.boolean().description('是否开启自动解析`选择对应视频 会自动解析视频内容`').default(true),
@@ -98,10 +98,14 @@ exports.Config = Schema.intersect([
98
98
 
99
99
  Schema.object({
100
100
  isfigure: Schema.boolean().default(false).description("是否开启合并转发 `仅支持 onebot 适配器` 其他平台开启 无效").experimental(),
101
- 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"),
102
101
  middleware: Schema.boolean().default(false).description("前置中间件模式"),
103
- loggerinfo: Schema.boolean().default(false).description("日志调试输出 `日常使用无需开启`"),
102
+ 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"),
104
103
  }).description("调试设置"),
104
+
105
+ Schema.object({
106
+ pageclose: Schema.boolean().default(true).description("自动`page.close()`<br>非开发者请勿改动").experimental(),
107
+ loggerinfo: Schema.boolean().default(false).description("日志调试输出 `日常使用无需开启`<br>非开发者请勿改动").experimental(),
108
+ }).description("开发者选项"),
105
109
  ]);
106
110
 
107
111
  function apply(ctx, config) {
@@ -316,7 +320,13 @@ display: none !important;
316
320
  width: 1440,
317
321
  height: viewportHeight
318
322
  })
323
+ logInfo("窗口:宽度:")
324
+ logInfo(1440)
325
+
326
+ logInfo("窗口:高度:")
327
+ logInfo(viewportHeight)
319
328
  let msg;
329
+
320
330
  // 截图
321
331
  const videoListElement = await page.$('.video-list.row')
322
332
  if (videoListElement) {
@@ -325,8 +335,9 @@ display: none !important;
325
335
  })
326
336
  msg = h.image(imgBuf, 'image/png')
327
337
  }
328
-
329
- await page.close()
338
+ if (page && config.pageclose) {
339
+ await page.close()
340
+ }
330
341
 
331
342
  // 发送截图
332
343
  await session.send(msg)
@@ -360,111 +371,6 @@ display: none !important;
360
371
  })
361
372
  }
362
373
 
363
- if (config.loggerinfo) {
364
- ctx.command('B站点播/调试点播 [keyword]', '调试时点播B站视频')
365
- .option('video', '-v 解析返回视频')
366
- .option('audio', '-a 解析返回语音')
367
- .option('link', '-l 解析返回链接')
368
- .option('page', '-p <page:number> 指定页数', { fallback: '1' })
369
- .example('调试点播 遠い空へ -v')
370
- .action(async ({ options, session }, keyword) => {
371
- if (!keyword) {
372
- await session.execute('调试点播 -h');
373
- return '没输入keyword';
374
- }
375
- const url = `https://search.bilibili.com/video?keyword=${encodeURIComponent(keyword)}&page=${options.page}&o=30`;
376
- const page = await ctx.puppeteer.page();
377
- await page.goto(url, {
378
- waitUntil: 'networkidle2',
379
- });
380
-
381
- // 获取视频列表并为每个视频元素添加序号
382
- const videos = await page.evaluate((point) => {
383
- const items = Array.from(document.querySelectorAll('.video-list-item:not([style*="display: none"])'));
384
- return items.map((item, index) => {
385
- const link = item.querySelector('a');
386
- const href = link?.getAttribute('href') || '';
387
- const idMatch = href.match(/\/video\/(BV\w+)\//);
388
- const id = idMatch ? idMatch[1] : '';
389
- if (!id) {
390
- const htmlElement = item;
391
- htmlElement.style.display = 'none';
392
- } else {
393
- const overlay = document.createElement('div');
394
- overlay.style.position = 'absolute';
395
- overlay.style.top = `${point[0]}%`;
396
- overlay.style.left = `${point[1]}%`;
397
- overlay.style.transform = 'translate(-50%, -50%)';
398
- overlay.style.fontSize = '48px';
399
- overlay.style.fontWeight = 'bold';
400
- overlay.style.color = 'black';
401
- overlay.style.zIndex = '10';
402
- overlay.style.backgroundColor = 'rgba(255, 255, 255, 0.7)';
403
- overlay.style.padding = '10px';
404
- overlay.style.borderRadius = '8px';
405
- overlay.textContent = `${index + 1}`;
406
- const videoElement = item;
407
- videoElement.style.position = 'relative';
408
- videoElement.appendChild(overlay);
409
- }
410
- return { id };
411
- }).filter(video => video.id);
412
- }, config.point);
413
-
414
- // 如果开启了日志调试模式,打印获取到的视频信息
415
- logInfo(options);
416
- logInfo(`共找到 ${videos.length} 个视频:`);
417
- videos.forEach((video, index) => {
418
- logInfo(`序号 ${index + 1}: ID - ${video.id}`);
419
- });
420
-
421
- if (videos.length === 0) {
422
- await page.close();
423
- return '未找到相关视频。';
424
- }
425
-
426
- // 动态调整窗口大小以适应视频数量
427
- const viewportHeight = 200 + videos.length * 100;
428
- await page.setViewport({
429
- width: 1440,
430
- height: viewportHeight,
431
- });
432
-
433
- let msg;
434
- // 截取整个页面
435
- const imgBuf = await page.screenshot({ fullPage: true });
436
- msg = h.image(imgBuf, 'image/png');
437
-
438
- await page.close();
439
-
440
- // 发送截图
441
- await session.send(msg);
442
- // 提示用户输入
443
- await session.send(`请选择视频的序号:`);
444
- // 等待用户输入
445
- const userChoice = await session.prompt(config.timeout * 1000);
446
- const choiceIndex = parseInt(userChoice) - 1;
447
- if (isNaN(choiceIndex) || choiceIndex < 0 || choiceIndex >= videos.length) {
448
- return '输入无效,请输入正确的序号。';
449
- }
450
-
451
- // 返回用户选择的视频ID
452
- const chosenVideo = videos[choiceIndex];
453
- // 如果开启了日志调试模式,打印用户选择的视频信息
454
- logInfo(`渲染序号设置\noverlay.style.top = ${config.point[0]}% \noverlay.style.left = ${config.point[1]}%`);
455
- logInfo(`用户选择了序号 ${choiceIndex + 1}: ID - ${chosenVideo.id}`);
456
-
457
-
458
- if (config.enable) {
459
- // 开启自动解析了
460
-
461
- const ret = await extractLinks(session, config, ctx, [{ type: 'Video', id: chosenVideo.id }], logger);
462
- if (ret && !isLinkProcessedRecently(ret, lastProcessedUrls, config, logger)) {
463
- await processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options);
464
- }
465
- }
466
- });
467
- }
468
374
  //判断是否需要解析
469
375
  async function isProcessLinks(sessioncontent) {
470
376
  // 解析内容中的链接
@@ -478,7 +384,9 @@ display: none !important;
478
384
  //提取链接
479
385
  async function extractLinks(session, config, ctx, links) {
480
386
  let ret = "";
481
- ret += [(0, h)("quote", { id: session.messageId })];
387
+ if (!config.isfigure) {
388
+ ret += [(0, h)("quote", { id: session.messageId })];
389
+ }
482
390
  let countLink = 0;
483
391
  let tp_ret;
484
392
 
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.13",
5
+ "version": "1.1.15",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [
package/readme.md CHANGED
@@ -178,6 +178,10 @@ https://www.bilibili.com/video/BV1ii421Q7oj
178
178
  <details>
179
179
  <summary>点击此处 可查看更新日志</summary>
180
180
 
181
+ - **1.1.14**
182
+ - 上次更新了什么?
183
+ - 新增page.close调试选项
184
+
181
185
  - **1.1.12**
182
186
  - 支持合并转发
183
187
  - 支持独立的AV号