koishi-plugin-video-parser-all 0.7.4 → 0.7.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.
- package/lib/index.js +44 -107
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -414,20 +414,17 @@ function findValueInObject(obj, keys) {
|
|
|
414
414
|
}
|
|
415
415
|
function parseData(rawResponse, maxDescLength) {
|
|
416
416
|
const root = rawResponse || {};
|
|
417
|
-
const data = root.data || root
|
|
418
|
-
// 小红书特殊处理:API返回数据在 root 根节点而非 data 子节点
|
|
419
|
-
const isXiaohongshu = root.note_title || root.note_desc || root.author_name || root.cover;
|
|
420
|
-
const parseRoot = isXiaohongshu ? root : data;
|
|
417
|
+
const data = root.data || root;
|
|
421
418
|
const stat = {};
|
|
422
419
|
let totalImageCount = 0;
|
|
423
420
|
Object.entries(VARIABLE_MAPPING).forEach(([varName, keys]) => {
|
|
424
|
-
let value = findValueInObject(
|
|
421
|
+
let value = findValueInObject(data, keys) || findValueInObject(root, keys);
|
|
425
422
|
if (varName === '图片数量' && value === undefined) {
|
|
426
423
|
let imgCount = 0;
|
|
427
424
|
const imgSources = [
|
|
428
|
-
|
|
425
|
+
data.images, data.pics, data.pic_urls, data.image_list, data.imgurl,
|
|
429
426
|
root.images, root.pics, root.pic_urls, root.image_list, root.imgurl,
|
|
430
|
-
|
|
427
|
+
data.item?.images
|
|
431
428
|
];
|
|
432
429
|
for (const source of imgSources) {
|
|
433
430
|
if (Array.isArray(source) && source.length > 0) {
|
|
@@ -436,8 +433,8 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
436
433
|
}
|
|
437
434
|
}
|
|
438
435
|
totalImageCount = imgCount;
|
|
439
|
-
const cover =
|
|
440
|
-
|
|
436
|
+
const cover = data.cover || data.video?.fm || data.imgurl || data.pic || data.thumbnail || data.cover_url ||
|
|
437
|
+
data.item?.cover || root.cover || data.live?.cover || data.live?.keyframe || '';
|
|
441
438
|
if (cover && imgCount > 0) {
|
|
442
439
|
imgCount = imgSources.find(source => Array.isArray(source))?.filter(i => i && typeof i === 'string' && i !== cover).length || 0;
|
|
443
440
|
}
|
|
@@ -447,118 +444,58 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
447
444
|
stat[varName] = value;
|
|
448
445
|
}
|
|
449
446
|
});
|
|
450
|
-
// 小红书字段兜底
|
|
451
|
-
if (isXiaohongshu) {
|
|
452
|
-
if (!stat['标题'])
|
|
453
|
-
stat['标题'] = root.note_title || root.title || '';
|
|
454
|
-
if (!stat['作者'])
|
|
455
|
-
stat['作者'] = root.author_name || root.nickname || root.author || '';
|
|
456
|
-
if (!stat['简介'])
|
|
457
|
-
stat['简介'] = root.note_desc || root.desc || root.content || '';
|
|
458
|
-
if (!stat['播放数'])
|
|
459
|
-
stat['播放数'] = root.play_count || root.view_count || '';
|
|
460
|
-
if (!stat['点赞数'])
|
|
461
|
-
stat['点赞数'] = root.like_count || root.attitudes_count || '';
|
|
462
|
-
if (!stat['评论数'])
|
|
463
|
-
stat['评论数'] = root.comment_count || root.comments_count || '';
|
|
464
|
-
if (!stat['收藏数'])
|
|
465
|
-
stat['收藏数'] = root.collect_count || root.favorite_count || '';
|
|
466
|
-
if (!stat['转发数'])
|
|
467
|
-
stat['转发数'] = root.share_count || root.repost_count || '';
|
|
468
|
-
if (!stat['发布时间'])
|
|
469
|
-
stat['发布时间'] = root.create_time || root.publish_time || '';
|
|
470
|
-
if (!stat['IP属地'])
|
|
471
|
-
stat['IP属地'] = root.ip_location || root.ip_info_str || '';
|
|
472
|
-
}
|
|
473
447
|
let type = 'video';
|
|
474
|
-
if (
|
|
475
|
-
type =
|
|
476
|
-
else if (
|
|
477
|
-
type =
|
|
448
|
+
if (data.jx?.type)
|
|
449
|
+
type = data.jx.type;
|
|
450
|
+
else if (data.type)
|
|
451
|
+
type = data.type;
|
|
478
452
|
else if (root.msg === 'cv')
|
|
479
453
|
type = 'cv';
|
|
480
454
|
else if (root.msg === 'live')
|
|
481
455
|
type = 'live';
|
|
482
|
-
else if ((
|
|
483
|
-
(
|
|
456
|
+
else if ((data.images && data.images.length > 1) || (root.images && root.images.length > 1) ||
|
|
457
|
+
(data.imgurl && data.imgurl.length > 1) || (root.imgurl && root.imgurl.length > 1))
|
|
484
458
|
type = '图集';
|
|
485
|
-
const title =
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
if (typeof author === 'object') {
|
|
490
|
-
author = '';
|
|
459
|
+
const title = data.title || '无标题';
|
|
460
|
+
let author = '';
|
|
461
|
+
if (data.author && typeof data.author === 'object') {
|
|
462
|
+
author = data.author.name || '';
|
|
491
463
|
}
|
|
492
464
|
else {
|
|
493
|
-
author = author || '
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
const
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
(Array.isArray(root.images) && root.images[0]) ||
|
|
503
|
-
(Array.isArray(parseRoot.imgurl) && parseRoot.imgurl[0]) || '';
|
|
504
|
-
let images = [];
|
|
505
|
-
const imgSources = [
|
|
506
|
-
parseRoot.images, parseRoot.pics, parseRoot.pic_urls, parseRoot.image_list, parseRoot.imgurl,
|
|
507
|
-
root.images, root.pics, root.pic_urls, root.image_list, root.imgurl,
|
|
508
|
-
parseRoot.item?.images
|
|
509
|
-
];
|
|
510
|
-
for (const source of imgSources) {
|
|
511
|
-
if (Array.isArray(source) && source.length > 0) {
|
|
512
|
-
images = source.filter(i => i && typeof i === 'string' && i !== cover);
|
|
513
|
-
break;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
let video = parseRoot.video?.url || parseRoot.url || parseRoot.download_url || parseRoot.playUrl ||
|
|
517
|
-
parseRoot.video_url || root.url || parseRoot.item?.url || parseRoot.live?.url ||
|
|
518
|
-
(parseRoot.live?.url && Array.isArray(parseRoot.live.url) ? parseRoot.live.url[0] : '') || '';
|
|
519
|
-
const durationValue = stat['视频时长'] || parseRoot.item?.duration || parseRoot.duration || 0;
|
|
465
|
+
author = data.author || '';
|
|
466
|
+
}
|
|
467
|
+
author = author || '未知作者';
|
|
468
|
+
const rawDesc = data.desc || data.content || '暂无简介';
|
|
469
|
+
const desc = rawDesc.slice(0, maxDescLength);
|
|
470
|
+
const cover = data.cover || '';
|
|
471
|
+
const images = Array.isArray(data.images) ? data.images : [];
|
|
472
|
+
const video = data.url || data.video_backup || '';
|
|
473
|
+
const durationValue = data.duration || 0;
|
|
520
474
|
const duration = typeof durationValue === 'number' ? durationValue : parseInt(durationValue) || 0;
|
|
521
475
|
const durationFormatted = formatDuration(durationValue);
|
|
522
|
-
const pubTime = formatPublishTime(
|
|
476
|
+
const pubTime = formatPublishTime(data.create_time || data.publish_time);
|
|
523
477
|
if (pubTime)
|
|
524
478
|
stat['发布时间'] = pubTime;
|
|
525
|
-
|
|
526
|
-
delete stat['发布时间'];
|
|
527
|
-
if (durationFormatted !== '00:00:00') {
|
|
479
|
+
if (durationFormatted !== '00:00:00')
|
|
528
480
|
stat['视频时长'] = durationFormatted;
|
|
529
|
-
|
|
530
|
-
else {
|
|
531
|
-
delete stat['视频时长'];
|
|
532
|
-
}
|
|
533
|
-
if (stat['图片数量'] === 0) {
|
|
481
|
+
if (stat['图片数量'] === 0)
|
|
534
482
|
delete stat['图片数量'];
|
|
483
|
+
const live_photo = data.live_photo || [];
|
|
484
|
+
const h_w = data.item?.h_w || [];
|
|
485
|
+
const quality_urls = data.quality_urls || {};
|
|
486
|
+
const default_quality = data.default_quality || '';
|
|
487
|
+
const download_url = video;
|
|
488
|
+
const play_count = stat['播放数'] || '';
|
|
489
|
+
const reposts_count = Number(stat['转发数']) || 0;
|
|
490
|
+
const attitudes_count = Number(stat['点赞数']) || 0;
|
|
491
|
+
const comments_count = Number(stat['评论数']) || 0;
|
|
492
|
+
if (data.live) {
|
|
493
|
+
stat['直播间地址'] = data.live.room_url || '';
|
|
494
|
+
stat['直播间ID'] = data.live.room_id || '';
|
|
495
|
+
stat['直播间状态'] = data.live.status === 1 ? '直播中' : (data.live.status === 0 ? '未开播' : '未知');
|
|
496
|
+
stat['在线人数'] = data.live.online || '';
|
|
497
|
+
stat['关注数'] = data.live.attention || '';
|
|
535
498
|
}
|
|
536
|
-
const sizeVal = stat['文件大小'];
|
|
537
|
-
if (sizeVal && !String(sizeVal).includes('MB')) {
|
|
538
|
-
const num = Number(sizeVal);
|
|
539
|
-
if (!isNaN(num) && num > 0)
|
|
540
|
-
stat['文件大小'] = `${num.toFixed(2)} MB`;
|
|
541
|
-
}
|
|
542
|
-
const live_photo = parseRoot.live_photo || root.live_photo || [];
|
|
543
|
-
const h_w = parseRoot.item?.h_w || root.h_w || [];
|
|
544
|
-
const quality_urls = parseRoot.quality_urls || root.quality_urls || {};
|
|
545
|
-
const default_quality = parseRoot.default_quality || root.default_quality || '';
|
|
546
|
-
const download_url = parseRoot.download_url || video;
|
|
547
|
-
const play_count = stat['播放数'] || parseRoot.play_count || root.play_count || '';
|
|
548
|
-
const reposts_count = Number(stat['转发数']) || parseRoot.reposts_count || root.reposts_count || 0;
|
|
549
|
-
const attitudes_count = Number(stat['点赞数']) || parseRoot.attitudes_count || root.attitudes_count || parseRoot.like || root.like || 0;
|
|
550
|
-
const comments_count = Number(stat['评论数']) || parseRoot.comments_count || root.comments_count || 0;
|
|
551
|
-
if (parseRoot.live) {
|
|
552
|
-
stat['直播间地址'] = parseRoot.live.room_url || '';
|
|
553
|
-
stat['直播间ID'] = parseRoot.live.room_id || '';
|
|
554
|
-
stat['直播间状态'] = parseRoot.live.status === 1 ? '直播中' : (parseRoot.live.status === 0 ? '未开播' : parseRoot.live.status || '未知');
|
|
555
|
-
stat['在线人数'] = parseRoot.live.online || '';
|
|
556
|
-
stat['关注数'] = parseRoot.live.attention || '';
|
|
557
|
-
}
|
|
558
|
-
if (parseRoot.followers_count)
|
|
559
|
-
stat['粉丝数'] = parseRoot.followers_count;
|
|
560
|
-
if (parseRoot.ip_info_str)
|
|
561
|
-
stat['IP属地'] = parseRoot.ip_info_str;
|
|
562
499
|
return {
|
|
563
500
|
type: type,
|
|
564
501
|
rawData: rawResponse,
|
|
@@ -574,7 +511,7 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
574
511
|
totalImageCount,
|
|
575
512
|
live_photo,
|
|
576
513
|
h_w,
|
|
577
|
-
jx:
|
|
514
|
+
jx: data.jx || null,
|
|
578
515
|
quality_urls,
|
|
579
516
|
default_quality,
|
|
580
517
|
download_url,
|
package/package.json
CHANGED