koishi-plugin-video-parser-all 0.6.5 → 0.6.6
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 +68 -48
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -141,31 +141,31 @@ const API_CONFIG = {
|
|
|
141
141
|
weibo: 'https://api.bugpk.com/api/weibo',
|
|
142
142
|
toutiao: 'https://api.bugpk.com/api/toutiao',
|
|
143
143
|
pipigx: 'https://api.bugpk.com/api/pipigx',
|
|
144
|
-
pipixia: 'https://api.bugpk.com/api/
|
|
144
|
+
pipixia: 'https://api.bugpk.com/api/pipixia',
|
|
145
145
|
zuiyou: 'https://api.bugpk.com/api/zuiyou'
|
|
146
146
|
};
|
|
147
147
|
const VARIABLE_MAPPING = {
|
|
148
|
-
'标题': ['title', 'Title', 'TITLE', 'note_title', 'content_title', 'item.title', 'data.title', 'video.title', 'live.title'],
|
|
149
|
-
'作者': ['author.name', 'author', 'name', 'Author', 'Name', 'owner.name', 'nickname', 'user_name', 'data.author', 'item.author', 'user.name', 'live.author'],
|
|
150
|
-
'简介': ['desc', 'description', 'Desc', 'Description', 'content', 'Content', 'note_desc', 'text', 'data.desc', 'item.description', 'live.desc'],
|
|
151
|
-
'视频时长': ['duration', 'Duration', 'time', 'Time', 'video_duration', 'item.duration', 'stat.duration'],
|
|
152
|
-
'点赞数': ['like', 'Like', 'attitudes_count', 'digg_count', 'praise', 'stat.like', 'liked_count', 'data.like', 'data.attitudes_count', 'item.attitudes_count'],
|
|
148
|
+
'标题': ['title', 'Title', 'TITLE', 'note_title', 'content_title', 'item.title', 'data.title', 'video.title', 'live.title', 'data.item.title'],
|
|
149
|
+
'作者': ['author.name', 'author', 'name', 'Author', 'Name', 'owner.name', 'nickname', 'user_name', 'data.author', 'item.author', 'user.name', 'live.author', 'data.user.name', 'data.author.name'],
|
|
150
|
+
'简介': ['desc', 'description', 'Desc', 'Description', 'content', 'Content', 'note_desc', 'text', 'data.desc', 'item.description', 'live.desc', 'data.item.description'],
|
|
151
|
+
'视频时长': ['duration', 'Duration', 'time', 'Time', 'video_duration', 'item.duration', 'stat.duration', 'data.item.duration'],
|
|
152
|
+
'点赞数': ['like', 'Like', 'attitudes_count', 'digg_count', 'praise', 'stat.like', 'liked_count', 'data.like', 'data.attitudes_count', 'item.attitudes_count', 'data.item.attitudes_count'],
|
|
153
153
|
'投币数': ['coin', 'Coin', 'bi', 'Bi', 'stat.coin', 'stast.coin'],
|
|
154
|
-
'收藏数': ['collect', 'Collect', 'favorite', 'Favorite', 'star', 'Star', 'stat.collect', 'collected_count', 'stast.favorite', 'data.favorite'],
|
|
155
|
-
'转发数': ['share', 'Share', 'forward', 'Forward', 'repost', 'stat.share', 'reposts_count', 'shared_count', 'stast.share', 'data.reposts_count'],
|
|
156
|
-
'播放数': ['view', 'View', 'play_count', 'PlayCount', 'play', 'stat.view', 'play_times', 'stast.view', 'data.play_count', 'item.play_count'],
|
|
157
|
-
'评论数': ['comment', 'Comment', 'comments_count', 'comment_count', 'discuss', 'stat.comment', 'stast.reply', 'data.comments_count', 'item.comments_count'],
|
|
158
|
-
'IP属地': ['ip_info_str', 'data.ip_info_str', 'item.ip_info'],
|
|
159
|
-
'发布时间': ['date', 'time', 'publish_time', 'data.date', 'item.publish_time', 'live.time', 'stast.publish_time'],
|
|
160
|
-
'粉丝数': ['followers_count', 'data.followers_count', 'item.followers', 'author.fans'],
|
|
161
|
-
'在线人数': ['online', 'data.online', 'live.online', 'room.online'],
|
|
162
|
-
'关注数': ['attention', 'data.attention', 'live.attention', 'stast.attention'],
|
|
163
|
-
'文件大小': ['size', 'size_str', 'item.size', 'item.size_str', 'data.size'],
|
|
164
|
-
'直播间地址': ['room_url', 'live.room_url', 'data.room_url', 'live.url'],
|
|
165
|
-
'直播间ID': ['room_id', 'live.room_id', 'data.room_id', 'live.room_id'],
|
|
166
|
-
'直播间状态': ['status', 'live.status', 'data.status', 'room.status'],
|
|
167
|
-
'图片数量': ['count', 'data.count', 'item.count', 'images.length', 'data.images.length'],
|
|
168
|
-
'作者ID': ['userId', 'userID', 'author_id', 'data.userId', 'item.userID', 'author.mid', 'user.mid'],
|
|
154
|
+
'收藏数': ['collect', 'Collect', 'favorite', 'Favorite', 'star', 'Star', 'stat.collect', 'collected_count', 'stast.favorite', 'data.favorite', 'stast.favorite'],
|
|
155
|
+
'转发数': ['share', 'Share', 'forward', 'Forward', 'repost', 'stat.share', 'reposts_count', 'shared_count', 'stast.share', 'data.reposts_count', 'data.item.reposts_count'],
|
|
156
|
+
'播放数': ['view', 'View', 'play_count', 'PlayCount', 'play', 'stat.view', 'play_times', 'stast.view', 'data.play_count', 'item.play_count', 'data.item.play_count'],
|
|
157
|
+
'评论数': ['comment', 'Comment', 'comments_count', 'comment_count', 'discuss', 'stat.comment', 'stast.reply', 'data.comments_count', 'item.comments_count', 'data.item.comments_count'],
|
|
158
|
+
'IP属地': ['ip_info_str', 'data.ip_info_str', 'item.ip_info', 'data.item.ip_info_str'],
|
|
159
|
+
'发布时间': ['date', 'time', 'publish_time', 'data.date', 'item.publish_time', 'live.time', 'stast.publish_time', 'stat.time', 'data.time.publish_time', 'data.live.time'],
|
|
160
|
+
'粉丝数': ['followers_count', 'data.followers_count', 'item.followers', 'author.fans', 'data.item.followers_count'],
|
|
161
|
+
'在线人数': ['online', 'data.online', 'live.online', 'room.online', 'data.live.online'],
|
|
162
|
+
'关注数': ['attention', 'data.attention', 'live.attention', 'stast.attention', 'data.live.attention'],
|
|
163
|
+
'文件大小': ['size', 'size_str', 'item.size', 'item.size_str', 'data.size', 'data.item.size_str'],
|
|
164
|
+
'直播间地址': ['room_url', 'live.room_url', 'data.room_url', 'live.url', 'data.live.room_url'],
|
|
165
|
+
'直播间ID': ['room_id', 'live.room_id', 'data.room_id', 'live.room_id', 'data.live.room_id'],
|
|
166
|
+
'直播间状态': ['status', 'live.status', 'data.status', 'room.status', 'data.live.status'],
|
|
167
|
+
'图片数量': ['count', 'data.count', 'item.count', 'images.length', 'data.images.length', 'data.item.count'],
|
|
168
|
+
'作者ID': ['userId', 'userID', 'author_id', 'data.userId', 'item.userID', 'author.mid', 'user.mid', 'data.item.userID', 'data.author_id', 'data.user.mid'],
|
|
169
169
|
};
|
|
170
170
|
function getErrorInfo(code, detail) {
|
|
171
171
|
const baseMsg = exports.ErrorMessageMap[code] || exports.ErrorMessageMap[ErrorCode.UNKNOWN_ERROR];
|
|
@@ -389,8 +389,11 @@ function formatPublishTime(value) {
|
|
|
389
389
|
if (!value)
|
|
390
390
|
return '';
|
|
391
391
|
const str = String(value).trim();
|
|
392
|
-
if (/^\d{10,}$/.test(str) && Number(str) > 1e12)
|
|
393
|
-
|
|
392
|
+
if (/^\d{10,}$/.test(str) && Number(str) > 1e12) {
|
|
393
|
+
if (Number(str) > 1e15) {
|
|
394
|
+
value = Number(str) / 1000;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
394
397
|
try {
|
|
395
398
|
const d = new Date(/^\d+$/.test(str) ? Number(str) * 1000 : str);
|
|
396
399
|
if (isNaN(d.getTime()))
|
|
@@ -412,7 +415,7 @@ function formatPublishTime(value) {
|
|
|
412
415
|
return parts.join(' ').trim();
|
|
413
416
|
}
|
|
414
417
|
catch {
|
|
415
|
-
return
|
|
418
|
+
return str;
|
|
416
419
|
}
|
|
417
420
|
}
|
|
418
421
|
function getNestedValue(obj, path) {
|
|
@@ -458,7 +461,10 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
458
461
|
Object.entries(VARIABLE_MAPPING).forEach(([varName, keys]) => {
|
|
459
462
|
let value = findValueInObject(data, keys) || findValueInObject(rootData, keys);
|
|
460
463
|
if (varName === '图片数量' && value === undefined) {
|
|
461
|
-
value = Array.isArray(data.images) ? data.images.length :
|
|
464
|
+
value = Array.isArray(data.images) ? data.images.length :
|
|
465
|
+
Array.isArray(rootData.images) ? rootData.images.length :
|
|
466
|
+
Array.isArray(data.imgurl) ? data.imgurl.length :
|
|
467
|
+
Array.isArray(rootData.imgurl) ? rootData.imgurl.length : undefined;
|
|
462
468
|
}
|
|
463
469
|
if (value !== undefined && value !== null && value !== '') {
|
|
464
470
|
stat[varName] = value;
|
|
@@ -473,21 +479,35 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
473
479
|
type = 'cv';
|
|
474
480
|
else if (rootData.msg === 'live')
|
|
475
481
|
type = 'live';
|
|
476
|
-
else if ((data.images && data.images.length > 1) || (rootData.images && rootData.images.length > 1)
|
|
482
|
+
else if ((data.images && data.images.length > 1) || (rootData.images && rootData.images.length > 1) ||
|
|
483
|
+
(data.imgurl && data.imgurl.length > 1) || (rootData.imgurl && rootData.imgurl.length > 1))
|
|
477
484
|
type = '图集';
|
|
478
|
-
const title = stat['标题'] ||
|
|
479
|
-
|
|
480
|
-
|
|
485
|
+
const title = stat['标题'] || data.note_title || data.title || data.content_title || data.item?.title || rootData.title || '无标题';
|
|
486
|
+
let author = stat['作者'] || data.author?.name || data.nickname || data.user_name || data.item?.author ||
|
|
487
|
+
rootData.author || data.user?.name || data.owner?.name || '未知作者';
|
|
488
|
+
if (typeof author === 'object' && author.name)
|
|
489
|
+
author = author.name;
|
|
490
|
+
const rawDesc = stat['简介'] || data.note_desc || data.content || data.text || data.description ||
|
|
491
|
+
data.item?.description || rootData.desc || rootData.description || '';
|
|
481
492
|
const desc = rawDesc.length > 0 ? rawDesc.slice(0, maxDescLength) : (title.length > 0 ? title : '暂无简介');
|
|
482
|
-
const cover = data.cover
|
|
493
|
+
const cover = data.cover || data.imgurl || data.pic || data.thumbnail || data.cover_url ||
|
|
494
|
+
data.item?.cover || rootData.cover || (Array.isArray(data.images) && data.images[0]) ||
|
|
495
|
+
(Array.isArray(rootData.images) && rootData.images[0]) || '';
|
|
483
496
|
let images = [];
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
images
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
497
|
+
const imgSources = [
|
|
498
|
+
data.images, data.pics, data.pic_urls, data.image_list, data.imgurl,
|
|
499
|
+
rootData.images, rootData.pics, rootData.pic_urls, rootData.image_list, rootData.imgurl,
|
|
500
|
+
data.item?.images
|
|
501
|
+
];
|
|
502
|
+
for (const source of imgSources) {
|
|
503
|
+
if (Array.isArray(source) && source.length > 0) {
|
|
504
|
+
images = source.filter(i => i && typeof i === 'string');
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
let video = data.video?.url || data.item?.url || data.url || data.download_url || data.playUrl ||
|
|
509
|
+
data.video_url || rootData.url || data.item?.url || '';
|
|
510
|
+
const durationValue = stat['视频时长'] || data.item?.duration || data.duration || 0;
|
|
491
511
|
const duration = typeof durationValue === 'number' ? durationValue : parseInt(durationValue) || 0;
|
|
492
512
|
const durationFormatted = formatDuration(durationValue);
|
|
493
513
|
const pubTime = formatPublishTime(stat['发布时间']);
|
|
@@ -506,15 +526,15 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
506
526
|
if (!isNaN(num) && num > 0)
|
|
507
527
|
stat['文件大小'] = `${num.toFixed(2)} MB`;
|
|
508
528
|
}
|
|
509
|
-
const live_photo = data.live_photo
|
|
510
|
-
const h_w = data.item?.h_w
|
|
511
|
-
const quality_urls = data.quality_urls
|
|
512
|
-
const default_quality = data.default_quality
|
|
513
|
-
const download_url = data.download_url
|
|
514
|
-
const play_count = stat['播放数']
|
|
515
|
-
const reposts_count = Number(stat['转发数']) || 0;
|
|
516
|
-
const attitudes_count = Number(stat['点赞数']) || 0;
|
|
517
|
-
const comments_count = Number(stat['评论数']) || 0;
|
|
529
|
+
const live_photo = data.live_photo || rootData.live_photo || [];
|
|
530
|
+
const h_w = data.item?.h_w || rootData.h_w || [];
|
|
531
|
+
const quality_urls = data.quality_urls || rootData.quality_urls || {};
|
|
532
|
+
const default_quality = data.default_quality || rootData.default_quality || '';
|
|
533
|
+
const download_url = data.download_url || video;
|
|
534
|
+
const play_count = stat['播放数'] || '';
|
|
535
|
+
const reposts_count = Number(stat['转发数']) || data.reposts_count || rootData.reposts_count || 0;
|
|
536
|
+
const attitudes_count = Number(stat['点赞数']) || data.attitudes_count || rootData.attitudes_count || 0;
|
|
537
|
+
const comments_count = Number(stat['评论数']) || data.comments_count || rootData.comments_count || 0;
|
|
518
538
|
return {
|
|
519
539
|
type: type,
|
|
520
540
|
rawData: rawResponse,
|
|
@@ -529,7 +549,7 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
529
549
|
stat,
|
|
530
550
|
live_photo,
|
|
531
551
|
h_w,
|
|
532
|
-
jx: data.jx
|
|
552
|
+
jx: data.jx || null,
|
|
533
553
|
quality_urls,
|
|
534
554
|
default_quality,
|
|
535
555
|
download_url,
|
|
@@ -663,7 +683,7 @@ function apply(ctx, config) {
|
|
|
663
683
|
}
|
|
664
684
|
const isSuccess = resData.code === 0 || resData.code === 200 || resData.code === 1 ||
|
|
665
685
|
(resData.msg && (resData.msg.includes('解析成功') || resData.msg.includes('success') || resData.msg.includes('请求成功'))) ||
|
|
666
|
-
!!resData.data || !!resData.result || !!resData.video || !!resData.images;
|
|
686
|
+
!!resData.data || !!resData.result || !!resData.video || !!resData.images || !!resData.imgurl;
|
|
667
687
|
if (!isSuccess) {
|
|
668
688
|
const apiErrorMsg = resData.msg || resData.error || '解析失败';
|
|
669
689
|
const code = ErrorCode.API_RETURN_ERROR;
|
package/package.json
CHANGED