koishi-plugin-video-parser-all 0.5.9 → 0.6.0

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 +39 -83
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -394,73 +394,55 @@ function parseData(rawResponse, maxDescLength) {
394
394
  const stat = {};
395
395
  Object.entries(VARIABLE_MAPPING).forEach(([varName, keys]) => {
396
396
  const value = findValueInObject(data, keys) || findValueInObject(rootData, keys);
397
- if (value !== undefined)
398
- stat[varName] = value;
397
+ stat[varName] = value;
399
398
  });
400
399
  let type = 'video';
401
400
  if (data.jx?.type)
402
401
  type = data.jx.type;
403
402
  else if (data.type)
404
403
  type = data.type;
405
- else if (data.images && data.images.length > 0)
406
- type = 'image';
407
- else if (data.pics && data.pics.length > 0)
408
- type = '图集';
409
- const title = findValueInObject(data, VARIABLE_MAPPING['标题']) || findValueInObject(rootData, VARIABLE_MAPPING['标题']) || '无标题';
410
- const author = findValueInObject(data, VARIABLE_MAPPING['作者']) || findValueInObject(rootData, VARIABLE_MAPPING['作者']) || '未知作者';
411
- let desc = findValueInObject(data, VARIABLE_MAPPING['简介']) || findValueInObject(rootData, VARIABLE_MAPPING['简介']) || title;
404
+ const title = data.title ?? data.note_title ?? data.content_title ?? stat['标题'] ?? '无标题';
405
+ const author = data.author?.name ?? data.nickname ?? data.user_name ?? stat['作者'] ?? '未知作者';
406
+ let desc = data.desc ?? data.content ?? data.note_desc ?? stat['简介'] ?? title;
412
407
  desc = desc.toString().slice(0, maxDescLength);
413
- const cover = findValueInObject(data, ['cover', 'imgurl', 'pic', 'thumbnail', 'cover_url']) || findValueInObject(rootData, ['cover', 'imgurl', 'pic', 'thumbnail', 'cover_url']) || '';
408
+ const cover = data.cover ?? data.imgurl ?? data.pic ?? data.thumbnail ?? data.cover_url ?? '';
414
409
  let images = [];
415
- const imgList = findValueInObject(data, ['images', 'pics', 'pic_urls', 'image_list']) || findValueInObject(rootData, ['images', 'pics', 'pic_urls', 'image_list']) || [];
416
- if (Array.isArray(imgList))
417
- images = imgList.filter(img => img && typeof img === 'string');
418
- else if (imgList && typeof imgList === 'string')
419
- images = [imgList];
410
+ const imgRaw = data.images ?? data.pics ?? data.pic_urls ?? data.image_list ?? [];
411
+ if (Array.isArray(imgRaw))
412
+ images = imgRaw.filter(i => i && typeof i === 'string');
413
+ else if (imgRaw)
414
+ images = [String(imgRaw)];
420
415
  let video = '';
421
- const videoUrls = [
422
- findValueInObject(data, ['url', 'video_url', 'download_url', 'playUrl', 'mp4_url']),
423
- findValueInObject(rootData, ['url', 'video_url', 'download_url', 'playUrl', 'mp4_url']),
424
- data.video?.url,
425
- data.item?.url,
426
- rootData.video?.url,
427
- rootData.item?.url
428
- ];
429
- for (const url of videoUrls) {
430
- if (url && typeof url === 'string' && url.startsWith('http')) {
431
- video = url;
432
- break;
433
- }
434
- }
435
- const durationValue = findValueInObject(data, VARIABLE_MAPPING['视频时长']) || findValueInObject(rootData, VARIABLE_MAPPING['视频时长']);
416
+ video = data.video?.url ?? data.item?.url ?? data.url ?? data.download_url ?? data.playUrl ?? data.video_url ?? '';
417
+ const durationValue = data.duration ?? stat['视频时长'] ?? 0;
436
418
  const duration = typeof durationValue === 'number' ? durationValue : parseInt(durationValue) || 0;
437
- const durationFormatted = formatDuration(durationValue || 0);
438
- const live_photo = data.live_photo || rootData.live_photo || [];
439
- const music = findValueInObject(data, VARIABLE_MAPPING['音乐名']) || findValueInObject(rootData, VARIABLE_MAPPING['音乐名']) || '';
440
- const h_w = data.item?.h_w || rootData.item?.h_w || [];
441
- const quality_urls = data.quality_urls || rootData.quality_urls || {};
442
- const default_quality = data.default_quality || rootData.default_quality || '';
443
- const download_url = data.download_url || rootData.download_url || video;
444
- const play_count = stat['播放数'] || '';
445
- const reposts_count = stat['转发数'] || 0;
446
- const attitudes_count = stat['点赞数'] || 0;
447
- const comments_count = stat['评论数'] || 0;
419
+ const durationFormatted = formatDuration(durationValue);
420
+ const live_photo = data.live_photo ?? [];
421
+ const music = data.music?.title ?? data.music ?? stat['音乐名'] ?? '';
422
+ const h_w = data.item?.h_w ?? [];
423
+ const quality_urls = data.quality_urls ?? {};
424
+ const default_quality = data.default_quality ?? '';
425
+ const download_url = data.download_url ?? video;
426
+ const play_count = stat['播放数'] ?? '';
427
+ const reposts_count = stat['转发数'] ?? 0;
428
+ const attitudes_count = stat['点赞数'] ?? 0;
429
+ const comments_count = stat['评论数'] ?? 0;
448
430
  return {
449
431
  type: type,
450
432
  rawData: rawResponse,
451
- title,
452
- author,
453
- desc,
454
- cover,
433
+ title: String(title),
434
+ author: String(author),
435
+ desc: String(desc),
436
+ cover: String(cover),
455
437
  images,
456
- video,
438
+ video: String(video),
457
439
  duration,
458
440
  durationFormatted,
459
441
  stat,
460
442
  live_photo,
461
- music,
443
+ music: String(music),
462
444
  h_w,
463
- jx: data.jx || rootData.jx || null,
445
+ jx: data.jx ?? null,
464
446
  quality_urls,
465
447
  default_quality,
466
448
  download_url,
@@ -474,37 +456,15 @@ function generateFormattedText(parseData, config) {
474
456
  let format = config.unifiedMessageFormat;
475
457
  if (!format)
476
458
  format = '标题:${标题}\n作者:${作者}\n简介:${简介}';
477
- const formatLines = format.split('\n');
478
- const validLines = [];
479
- formatLines.forEach((line) => {
480
- if (!line.trim())
481
- return;
482
- let isValid = true;
483
- let processedLine = line;
484
- const varMatches = line.match(/\$\{([^}]+)\}/g) || [];
485
- if (varMatches.length === 0) {
486
- validLines.push(line);
487
- return;
488
- }
489
- varMatches.forEach((varMatch) => {
490
- const varName = varMatch.replace(/\$\{|\}/g, '');
491
- const value = parseData.stat[varName];
492
- if (value === undefined || value === null || value === '' || value === 0 || value === '00:00') {
493
- isValid = false;
494
- }
495
- else {
496
- processedLine = processedLine.replace(varMatch, String(value));
497
- }
498
- });
499
- if (isValid && processedLine.trim() !== '') {
500
- validLines.push(processedLine);
501
- }
459
+ let result = format;
460
+ const varMatches = result.match(/\$\{([^}]+)\}/g) || [];
461
+ varMatches.forEach((varMatch) => {
462
+ const varName = varMatch.replace(/\$\{|\}/g, '');
463
+ const value = parseData.stat[varName];
464
+ const showValue = value ?? '';
465
+ result = result.replace(varMatch, String(showValue));
502
466
  });
503
- let result = validLines.join('\n').trim();
504
- if (!result) {
505
- result = `标题:${parseData.title}\n作者:${parseData.author}\n简介:${parseData.desc}`;
506
- }
507
- return result;
467
+ return result.trim() || `标题:${parseData.title}\n作者:${parseData.author}\n简介:${parseData.desc}`;
508
468
  }
509
469
  function clearAllCache() {
510
470
  processed.clear();
@@ -611,11 +571,7 @@ function apply(ctx, config) {
611
571
  }
612
572
  try {
613
573
  const parseResult = parseData(resData, config.maxDescLength);
614
- const hasValidContent = parseResult.video ||
615
- (parseResult.images && parseResult.images.length > 0) ||
616
- (parseResult.live_photo && parseResult.live_photo.length > 0) ||
617
- parseResult.type === 'live' ||
618
- parseResult.type === '图集';
574
+ const hasValidContent = true;
619
575
  if (!hasValidContent) {
620
576
  const code = ErrorCode.NO_VIDEO_FOUND;
621
577
  const msg = getErrorInfo(code, '链接有效但未获取到有效视频/图片内容,可能是私密/需要登录/已删除内容');
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.5.9",
4
+ "version": "0.6.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [