koishi-plugin-video-parser-all 0.6.4 → 0.6.5

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 +49 -22
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -38,13 +38,9 @@ IP属地:${'${IP属地}'}
38
38
  在线人数:${'${在线人数}'}
39
39
  关注数:${'${关注数}'}
40
40
  文件大小:${'${文件大小}'}
41
- 分辨率:${'${分辨率}'}
42
- 音乐作者:${'${音乐作者}'}
43
- 音乐标题:${'${音乐标题}'}
44
41
  直播间地址:${'${直播间地址}'}
45
42
  直播间ID:${'${直播间ID}'}
46
43
  直播间状态:${'${直播间状态}'}
47
- 默认画质:${'${默认画质}'}
48
44
  图片数量:${'${图片数量}'}
49
45
  作者ID:${'${作者ID}'}`).description('统一消息格式'),
50
46
  }).description('统一消息格式'),
@@ -165,13 +161,9 @@ const VARIABLE_MAPPING = {
165
161
  '在线人数': ['online', 'data.online', 'live.online', 'room.online'],
166
162
  '关注数': ['attention', 'data.attention', 'live.attention', 'stast.attention'],
167
163
  '文件大小': ['size', 'size_str', 'item.size', 'item.size_str', 'data.size'],
168
- '分辨率': ['height', 'width', 'h_w', 'item.h_w', 'data.resolution', 'item.height', 'item.width'],
169
- '音乐作者': ['music.author', 'item.music.author', 'data.music.author', 'music.artist'],
170
- '音乐标题': ['music.title', 'item.music.title', 'data.music.title', 'music.name'],
171
164
  '直播间地址': ['room_url', 'live.room_url', 'data.room_url', 'live.url'],
172
165
  '直播间ID': ['room_id', 'live.room_id', 'data.room_id', 'live.room_id'],
173
166
  '直播间状态': ['status', 'live.status', 'data.status', 'room.status'],
174
- '默认画质': ['default_quality', 'data.default_quality', 'item.default_quality'],
175
167
  '图片数量': ['count', 'data.count', 'item.count', 'images.length', 'data.images.length'],
176
168
  '作者ID': ['userId', 'userID', 'author_id', 'data.userId', 'item.userID', 'author.mid', 'user.mid'],
177
169
  };
@@ -393,6 +385,36 @@ function formatDuration(input) {
393
385
  const secs = Math.floor(seconds % 60);
394
386
  return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
395
387
  }
388
+ function formatPublishTime(value) {
389
+ if (!value)
390
+ return '';
391
+ const str = String(value).trim();
392
+ if (/^\d{10,}$/.test(str) && Number(str) > 1e12)
393
+ return '';
394
+ try {
395
+ const d = new Date(/^\d+$/.test(str) ? Number(str) * 1000 : str);
396
+ if (isNaN(d.getTime()))
397
+ return '';
398
+ const y = d.getFullYear();
399
+ const m = (d.getMonth() + 1).toString().padStart(2, '0');
400
+ const d_ = d.getDate().toString().padStart(2, '0');
401
+ const H = d.getHours().toString().padStart(2, '0');
402
+ const i = d.getMinutes().toString().padStart(2, '0');
403
+ const parts = [];
404
+ if (y > 2000)
405
+ parts.push(`${y}年`);
406
+ if (m)
407
+ parts.push(`${m}月`);
408
+ if (d_)
409
+ parts.push(`${d_}日`);
410
+ if (H && i)
411
+ parts.push(`${H}:${i}`);
412
+ return parts.join(' ').trim();
413
+ }
414
+ catch {
415
+ return '';
416
+ }
417
+ }
396
418
  function getNestedValue(obj, path) {
397
419
  if (!obj || typeof obj !== 'object' || !path)
398
420
  return undefined;
@@ -438,14 +460,6 @@ function parseData(rawResponse, maxDescLength) {
438
460
  if (varName === '图片数量' && value === undefined) {
439
461
  value = Array.isArray(data.images) ? data.images.length : (Array.isArray(rootData.images) ? rootData.images.length : undefined);
440
462
  }
441
- if (varName === '分辨率' && value === undefined) {
442
- const h = findValueInObject(data, ['height', 'item.height']) || findValueInObject(rootData, ['height', 'item.height']);
443
- const w = findValueInObject(data, ['width', 'item.width']) || findValueInObject(rootData, ['width', 'item.width']);
444
- if (h && w)
445
- value = `${w}x${h}`;
446
- else if (data.h_w && Array.isArray(data.h_w) && data.h_w.length)
447
- value = data.h_w.join(', ');
448
- }
449
463
  if (value !== undefined && value !== null && value !== '') {
450
464
  stat[varName] = value;
451
465
  }
@@ -476,8 +490,23 @@ function parseData(rawResponse, maxDescLength) {
476
490
  const durationValue = stat['视频时长'] || 0;
477
491
  const duration = typeof durationValue === 'number' ? durationValue : parseInt(durationValue) || 0;
478
492
  const durationFormatted = formatDuration(durationValue);
493
+ const pubTime = formatPublishTime(stat['发布时间']);
494
+ if (pubTime)
495
+ stat['发布时间'] = pubTime;
496
+ else
497
+ delete stat['发布时间'];
498
+ const durShow = durationFormatted === '00:00:00' && (String(durationValue).length > 12) ? '' : durationFormatted;
499
+ if (durShow)
500
+ stat['视频时长'] = durShow;
501
+ else
502
+ delete stat['视频时长'];
503
+ const sizeVal = stat['文件大小'];
504
+ if (sizeVal && !String(sizeVal).includes('MB')) {
505
+ const num = Number(sizeVal);
506
+ if (!isNaN(num) && num > 0)
507
+ stat['文件大小'] = `${num.toFixed(2)} MB`;
508
+ }
479
509
  const live_photo = data.live_photo ?? [];
480
- const music = stat['音乐名'] || '';
481
510
  const h_w = data.item?.h_w ?? [];
482
511
  const quality_urls = data.quality_urls ?? {};
483
512
  const default_quality = data.default_quality ?? '';
@@ -499,7 +528,6 @@ function parseData(rawResponse, maxDescLength) {
499
528
  durationFormatted,
500
529
  stat,
501
530
  live_photo,
502
- music: String(music),
503
531
  h_w,
504
532
  jx: data.jx ?? null,
505
533
  quality_urls,
@@ -699,7 +727,6 @@ function apply(ctx, config) {
699
727
  video: parseData.video,
700
728
  type: parseData.type,
701
729
  live_photo: parseData.live_photo,
702
- music: parseData.music,
703
730
  h_w: parseData.h_w,
704
731
  quality_urls: parseData.quality_urls,
705
732
  default_quality: parseData.default_quality,
@@ -784,7 +811,7 @@ function apply(ctx, config) {
784
811
  forwardMessages.push(buildForwardNode(session, koishi_1.h.file(dl.filePath), botName));
785
812
  }
786
813
  else {
787
- forwardMessages.push(buildForwardNode(session, koishi_1.h.text(`视频:${item.video}`), botName));
814
+ forwardMessages.push(buildForwardNode(session, koishi_1.h.video(item.video), botName));
788
815
  }
789
816
  }
790
817
  else {
@@ -792,7 +819,7 @@ function apply(ctx, config) {
792
819
  }
793
820
  }
794
821
  catch (e) {
795
- forwardMessages.push(buildForwardNode(session, koishi_1.h.text(`视频:${item.video}`), botName));
822
+ forwardMessages.push(buildForwardNode(session, koishi_1.h.video(item.video), botName));
796
823
  }
797
824
  }
798
825
  }
@@ -816,7 +843,7 @@ function apply(ctx, config) {
816
843
  await sendTimeout(session, koishi_1.h.video(item.video));
817
844
  }
818
845
  catch (e) {
819
- await sendTimeout(session, `视频:${item.video}`);
846
+ await sendTimeout(session, koishi_1.h.video(item.video));
820
847
  }
821
848
  await delay(500);
822
849
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-video-parser-all",
3
3
  "description": "Koishi 全平台视频解析插件,支持抖音/快手/B站/小红书/微博/今日头条/皮皮搞笑/皮皮虾/最右视频链接解析",
4
- "version": "0.6.4",
4
+ "version": "0.6.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [