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

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 +23 -35
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -32,15 +32,11 @@ exports.Config = koishi_1.Schema.intersect([
32
32
  转发:${'${转发数}'}
33
33
  播放:${'${播放数}'}
34
34
  评论:${'${评论数}'}
35
- 音乐:${'${音乐名}'}
36
35
  IP属地:${'${IP属地}'}
37
36
  发布时间:${'${发布时间}'}
38
37
  粉丝数:${'${粉丝数}'}
39
38
  在线人数:${'${在线人数}'}
40
39
  关注数:${'${关注数}'}
41
- 视频质量:${'${视频质量}'}
42
- 帧率:${'${帧率}'}
43
- 码率:${'${码率}'}
44
40
  文件大小:${'${文件大小}'}
45
41
  分辨率:${'${分辨率}'}
46
42
  音乐作者:${'${音乐作者}'}
@@ -50,9 +46,7 @@ IP属地:${'${IP属地}'}
50
46
  直播间状态:${'${直播间状态}'}
51
47
  默认画质:${'${默认画质}'}
52
48
  图片数量:${'${图片数量}'}
53
- 作者ID:${'${作者ID}'}
54
- 封面链接:${'${封面链接}'}
55
- 视频链接:${'${视频链接}'}`).description('统一消息格式(无法获取的变量会自动隐藏)'),
49
+ 作者ID:${'${作者ID}'}`).description('统一消息格式'),
56
50
  }).description('统一消息格式'),
57
51
  koishi_1.Schema.object({
58
52
  showImageText: koishi_1.Schema.boolean().default(true).description('显示图文内容'),
@@ -75,10 +69,10 @@ IP属地:${'${IP属地}'}
75
69
  enableForward: koishi_1.Schema.boolean().default(false).description('启用合并转发(仅OneBot平台)'),
76
70
  downloadVideoBeforeSend: koishi_1.Schema.boolean().default(false).description('发送前先下载视频'),
77
71
  maxVideoSize: koishi_1.Schema.number().min(0).default(0).description('最大视频大小限制(MB,0为不限制)'),
78
- downloadThreads: koishi_1.Schema.number().min(0).max(10).default(0).description('多线程下载线程数(0为不使用多线程,1-10为启用对应线程数)'),
72
+ downloadThreads: koishi_1.Schema.number().min(0).max(10).default(0).description('多线程下载线程数(0为不使用多线程)'),
79
73
  }).description('发送方式设置'),
80
74
  koishi_1.Schema.object({
81
- messageBufferDelay: koishi_1.Schema.number().min(0).default(0).description('消息缓冲延迟(毫秒,批量处理链接)'),
75
+ messageBufferDelay: koishi_1.Schema.number().min(0).default(0).description('消息缓冲延迟(毫秒)'),
82
76
  }).description('消息处理设置'),
83
77
  koishi_1.Schema.object({
84
78
  autoClearCacheInterval: koishi_1.Schema.number().min(0).default(0).description('自动清理缓存间隔(分钟,0为关闭)'),
@@ -114,7 +108,7 @@ exports.ErrorMessageMap = {
114
108
  [ErrorCode.PLATFORM_API_NOT_CONFIGURED]: '该平台暂未配置解析接口',
115
109
  [ErrorCode.REQUEST_TIMEOUT]: '请求超时',
116
110
  [ErrorCode.NETWORK_ERROR]: '网络请求失败',
117
- [ErrorCode.DUPLICATE_PARSE]: '请勿重复解析(相同链接解析间隔未到)',
111
+ [ErrorCode.DUPLICATE_PARSE]: '请勿重复解析',
118
112
  [ErrorCode.INVALID_URL]: '无效的链接格式',
119
113
  [ErrorCode.API_RETURN_ERROR]: 'API返回错误',
120
114
  [ErrorCode.API_DATA_PARSE_FAILED]: '数据解析异常',
@@ -165,15 +159,11 @@ const VARIABLE_MAPPING = {
165
159
  '转发数': ['share', 'Share', 'forward', 'Forward', 'repost', 'stat.share', 'reposts_count', 'shared_count', 'stast.share', 'data.reposts_count'],
166
160
  '播放数': ['view', 'View', 'play_count', 'PlayCount', 'play', 'stat.view', 'play_times', 'stast.view', 'data.play_count', 'item.play_count'],
167
161
  '评论数': ['comment', 'Comment', 'comments_count', 'comment_count', 'discuss', 'stat.comment', 'stast.reply', 'data.comments_count', 'item.comments_count'],
168
- '音乐名': ['music.title', 'music_name', 'audio_name', 'sound_name', 'muisic', 'music', 'bgm_name', 'data.music.name', 'item.music.title', 'music.author', 'music.albumName'],
169
162
  'IP属地': ['ip_info_str', 'data.ip_info_str', 'item.ip_info'],
170
163
  '发布时间': ['date', 'time', 'publish_time', 'data.date', 'item.publish_time', 'live.time', 'stast.publish_time'],
171
164
  '粉丝数': ['followers_count', 'data.followers_count', 'item.followers', 'author.fans'],
172
165
  '在线人数': ['online', 'data.online', 'live.online', 'room.online'],
173
166
  '关注数': ['attention', 'data.attention', 'live.attention', 'stast.attention'],
174
- '视频质量': ['quality', 'max_qxd', 'data.quality', 'item.quality', 'quality_urls'],
175
- '帧率': ['fps', 'item.fps', 'data.fps'],
176
- '码率': ['bitrate', 'item.bitrate', 'data.bitrate', 'br', 'item.br'],
177
167
  '文件大小': ['size', 'size_str', 'item.size', 'item.size_str', 'data.size'],
178
168
  '分辨率': ['height', 'width', 'h_w', 'item.h_w', 'data.resolution', 'item.height', 'item.width'],
179
169
  '音乐作者': ['music.author', 'item.music.author', 'data.music.author', 'music.artist'],
@@ -184,8 +174,6 @@ const VARIABLE_MAPPING = {
184
174
  '默认画质': ['default_quality', 'data.default_quality', 'item.default_quality'],
185
175
  '图片数量': ['count', 'data.count', 'item.count', 'images.length', 'data.images.length'],
186
176
  '作者ID': ['userId', 'userID', 'author_id', 'data.userId', 'item.userID', 'author.mid', 'user.mid'],
187
- '封面链接': ['cover', 'imgurl', 'pic', 'thumbnail', 'cover_url', 'data.cover', 'item.cover', 'live.cover'],
188
- '视频链接': ['url', 'video_url', 'playUrl', 'download_url', 'data.url', 'item.url', 'live.url', 'quality_urls.*'],
189
177
  };
190
178
  function getErrorInfo(code, detail) {
191
179
  const baseMsg = exports.ErrorMessageMap[code] || exports.ErrorMessageMap[ErrorCode.UNKNOWN_ERROR];
@@ -375,7 +363,6 @@ async function resolveShortUrl(url) {
375
363
  headers: {
376
364
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
377
365
  'Referer': 'https://www.baidu.com/',
378
- 'Cookie': 'xhsTrackerId=xxx; xhs_sessionId=xxx'
379
366
  }
380
367
  });
381
368
  return cleanUrl(res.request.res?.responseUrl || url);
@@ -386,21 +373,25 @@ async function resolveShortUrl(url) {
386
373
  }
387
374
  function formatDuration(input) {
388
375
  if (!input || input === 0 || input === '0' || input === '00:00')
389
- return '00:00';
376
+ return '00:00:00';
390
377
  if (typeof input === 'string') {
391
- if (input.includes(':'))
392
- return input;
378
+ if (input.includes(':')) {
379
+ const parts = input.split(':');
380
+ if (parts.length === 2)
381
+ return `00:${parts[0].padStart(2, '0')}:${parts[1].padStart(2, '0')}`;
382
+ if (parts.length === 3)
383
+ return `${parts[0].padStart(2, '0')}:${parts[1].padStart(2, '0')}:${parts[2].padStart(2, '0')}`;
384
+ return '00:00:00';
385
+ }
393
386
  input = Number(input);
394
387
  }
395
388
  const seconds = Math.floor(Number(input));
396
- if (isNaN(seconds) || seconds <= 0)
397
- return '00:00';
389
+ if (isNaN(seconds) || seconds <= 0 || seconds > 315360000)
390
+ return '00:00:00';
398
391
  const hours = Math.floor(seconds / 3600);
399
392
  const minutes = Math.floor((seconds % 3600) / 60);
400
393
  const secs = Math.floor(seconds % 60);
401
- return hours > 0
402
- ? `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
403
- : `${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
394
+ return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
404
395
  }
405
396
  function getNestedValue(obj, path) {
406
397
  if (!obj || typeof obj !== 'object' || !path)
@@ -455,9 +446,6 @@ function parseData(rawResponse, maxDescLength) {
455
446
  else if (data.h_w && Array.isArray(data.h_w) && data.h_w.length)
456
447
  value = data.h_w.join(', ');
457
448
  }
458
- if (varName === '视频链接' && value === undefined) {
459
- value = data.url || data.video || data.download_url || rootData.url || rootData.video;
460
- }
461
449
  if (value !== undefined && value !== null && value !== '') {
462
450
  stat[varName] = value;
463
451
  }
@@ -471,12 +459,13 @@ function parseData(rawResponse, maxDescLength) {
471
459
  type = 'cv';
472
460
  else if (rootData.msg === 'live')
473
461
  type = 'live';
474
- else if (data.images && data.images.length > 0 && !data.url)
462
+ else if ((data.images && data.images.length > 1) || (rootData.images && rootData.images.length > 1))
475
463
  type = '图集';
476
- const title = stat['标题'] || '无标题';
477
- const author = stat['作者'] || '未知作者';
478
- const desc = (stat['简介'] || title).slice(0, maxDescLength);
479
- const cover = data.cover ?? data.imgurl ?? data.pic ?? data.thumbnail ?? data.cover_url ?? '';
464
+ const title = stat['标题'] || (data.note_title || data.title || data.content_title || '无标题');
465
+ const author = stat['作者'] || (data.author?.name || data.nickname || data.user_name || '未知作者');
466
+ const rawDesc = stat['简介'] || data.note_desc || data.content || data.text || data.description || '';
467
+ const desc = rawDesc.length > 0 ? rawDesc.slice(0, maxDescLength) : (title.length > 0 ? title : '暂无简介');
468
+ const cover = data.cover ?? data.imgurl ?? data.pic ?? data.thumbnail ?? data.cover_url ?? (Array.isArray(data.images) && data.images[0] ? data.images[0] : '');
480
469
  let images = [];
481
470
  const imgRaw = data.images ?? data.pics ?? data.pic_urls ?? data.image_list ?? [];
482
471
  if (Array.isArray(imgRaw))
@@ -534,8 +523,7 @@ function generateFormattedText(parseData, config) {
534
523
  收藏:${'${收藏数}'}
535
524
  转发:${'${转发数}'}
536
525
  播放:${'${播放数}'}
537
- 评论:${'${评论数}'}
538
- 音乐:${'${音乐名}'}`;
526
+ 评论:${'${评论数}'}`;
539
527
  }
540
528
  let result = format;
541
529
  const varMatches = result.match(/\$\{([^}]+)\}/g) || [];
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.3",
4
+ "version": "0.6.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [