koishi-plugin-video-parser-all 0.7.3 → 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 +27 -64
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -414,7 +414,7 @@ function findValueInObject(obj, keys) {
|
|
|
414
414
|
}
|
|
415
415
|
function parseData(rawResponse, maxDescLength) {
|
|
416
416
|
const root = rawResponse || {};
|
|
417
|
-
const data = root.data || root
|
|
417
|
+
const data = root.data || root;
|
|
418
418
|
const stat = {};
|
|
419
419
|
let totalImageCount = 0;
|
|
420
420
|
Object.entries(VARIABLE_MAPPING).forEach(([varName, keys]) => {
|
|
@@ -456,83 +456,46 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
456
456
|
else if ((data.images && data.images.length > 1) || (root.images && root.images.length > 1) ||
|
|
457
457
|
(data.imgurl && data.imgurl.length > 1) || (root.imgurl && root.imgurl.length > 1))
|
|
458
458
|
type = '图集';
|
|
459
|
-
const title =
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
if (typeof author === 'object') {
|
|
464
|
-
author = '';
|
|
459
|
+
const title = data.title || '无标题';
|
|
460
|
+
let author = '';
|
|
461
|
+
if (data.author && typeof data.author === 'object') {
|
|
462
|
+
author = data.author.name || '';
|
|
465
463
|
}
|
|
466
464
|
else {
|
|
467
|
-
author = author || '
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
const
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
(Array.isArray(root.images) && root.images[0]) ||
|
|
477
|
-
(Array.isArray(data.imgurl) && data.imgurl[0]) || '';
|
|
478
|
-
let images = [];
|
|
479
|
-
const imgSources = [
|
|
480
|
-
data.images, data.pics, data.pic_urls, data.image_list, data.imgurl,
|
|
481
|
-
root.images, root.pics, root.pic_urls, root.image_list, root.imgurl,
|
|
482
|
-
data.item?.images
|
|
483
|
-
];
|
|
484
|
-
for (const source of imgSources) {
|
|
485
|
-
if (Array.isArray(source) && source.length > 0) {
|
|
486
|
-
images = source.filter(i => i && typeof i === 'string' && i !== cover);
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
let video = data.video?.url || data.url || data.download_url || data.playUrl ||
|
|
491
|
-
data.video_url || root.url || data.item?.url || data.live?.url ||
|
|
492
|
-
(data.live?.url && Array.isArray(data.live.url) ? data.live.url[0] : '') || '';
|
|
493
|
-
const durationValue = stat['视频时长'] || data.item?.duration || data.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;
|
|
494
474
|
const duration = typeof durationValue === 'number' ? durationValue : parseInt(durationValue) || 0;
|
|
495
475
|
const durationFormatted = formatDuration(durationValue);
|
|
496
|
-
const pubTime = formatPublishTime(
|
|
476
|
+
const pubTime = formatPublishTime(data.create_time || data.publish_time);
|
|
497
477
|
if (pubTime)
|
|
498
478
|
stat['发布时间'] = pubTime;
|
|
499
|
-
|
|
500
|
-
delete stat['发布时间'];
|
|
501
|
-
if (durationFormatted !== '00:00:00') {
|
|
479
|
+
if (durationFormatted !== '00:00:00')
|
|
502
480
|
stat['视频时长'] = durationFormatted;
|
|
503
|
-
|
|
504
|
-
else {
|
|
505
|
-
delete stat['视频时长'];
|
|
506
|
-
}
|
|
507
|
-
if (stat['图片数量'] === 0) {
|
|
481
|
+
if (stat['图片数量'] === 0)
|
|
508
482
|
delete stat['图片数量'];
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
const
|
|
517
|
-
const
|
|
518
|
-
const quality_urls = data.quality_urls || root.quality_urls || {};
|
|
519
|
-
const default_quality = data.default_quality || root.default_quality || '';
|
|
520
|
-
const download_url = data.download_url || video;
|
|
521
|
-
const play_count = stat['播放数'] || data.play_count || root.play_count || '';
|
|
522
|
-
const reposts_count = Number(stat['转发数']) || data.reposts_count || root.reposts_count || 0;
|
|
523
|
-
const attitudes_count = Number(stat['点赞数']) || data.attitudes_count || root.attitudes_count || data.like || root.like || 0;
|
|
524
|
-
const comments_count = Number(stat['评论数']) || data.comments_count || root.comments_count || 0;
|
|
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;
|
|
525
492
|
if (data.live) {
|
|
526
493
|
stat['直播间地址'] = data.live.room_url || '';
|
|
527
494
|
stat['直播间ID'] = data.live.room_id || '';
|
|
528
|
-
stat['直播间状态'] = data.live.status === 1 ? '直播中' : (data.live.status === 0 ? '未开播' :
|
|
495
|
+
stat['直播间状态'] = data.live.status === 1 ? '直播中' : (data.live.status === 0 ? '未开播' : '未知');
|
|
529
496
|
stat['在线人数'] = data.live.online || '';
|
|
530
497
|
stat['关注数'] = data.live.attention || '';
|
|
531
498
|
}
|
|
532
|
-
if (data.followers_count)
|
|
533
|
-
stat['粉丝数'] = data.followers_count;
|
|
534
|
-
if (data.ip_info_str)
|
|
535
|
-
stat['IP属地'] = data.ip_info_str;
|
|
536
499
|
return {
|
|
537
500
|
type: type,
|
|
538
501
|
rawData: rawResponse,
|
package/package.json
CHANGED