koishi-plugin-video-parser-all 0.6.8 → 0.6.9
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 +77 -58
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -15,12 +15,12 @@ const worker_threads_1 = require("worker_threads");
|
|
|
15
15
|
exports.name = 'video-parser-all';
|
|
16
16
|
exports.Config = koishi_1.Schema.intersect([
|
|
17
17
|
koishi_1.Schema.object({
|
|
18
|
-
enable: koishi_1.Schema.boolean().default(true)
|
|
19
|
-
botName: koishi_1.Schema.string().default('视频解析机器人')
|
|
20
|
-
showWaitingTip: koishi_1.Schema.boolean().default(true)
|
|
21
|
-
waitingTipText: koishi_1.Schema.string().default('正在解析视频,请稍候...')
|
|
22
|
-
sameLinkInterval: koishi_1.Schema.number().min(0).default(180)
|
|
23
|
-
})
|
|
18
|
+
enable: koishi_1.Schema.boolean().default(true),
|
|
19
|
+
botName: koishi_1.Schema.string().default('视频解析机器人'),
|
|
20
|
+
showWaitingTip: koishi_1.Schema.boolean().default(true),
|
|
21
|
+
waitingTipText: koishi_1.Schema.string().default('正在解析视频,请稍候...'),
|
|
22
|
+
sameLinkInterval: koishi_1.Schema.number().min(0).default(180),
|
|
23
|
+
}),
|
|
24
24
|
koishi_1.Schema.object({
|
|
25
25
|
unifiedMessageFormat: koishi_1.Schema.string().role('textarea').default(`标题:${'${标题}'}
|
|
26
26
|
作者:${'${作者}'}
|
|
@@ -42,38 +42,37 @@ IP属地:${'${IP属地}'}
|
|
|
42
42
|
直播间ID:${'${直播间ID}'}
|
|
43
43
|
直播间状态:${'${直播间状态}'}
|
|
44
44
|
图片数量:${'${图片数量}'}
|
|
45
|
-
作者ID:${'${作者ID}'}
|
|
46
|
-
|
|
47
|
-
}).description('统一消息格式'),
|
|
45
|
+
作者ID:${'${作者ID}'}`),
|
|
46
|
+
}),
|
|
48
47
|
koishi_1.Schema.object({
|
|
49
|
-
showImageText: koishi_1.Schema.boolean().default(true)
|
|
50
|
-
showVideoFile: koishi_1.Schema.boolean().default(true)
|
|
51
|
-
})
|
|
48
|
+
showImageText: koishi_1.Schema.boolean().default(true),
|
|
49
|
+
showVideoFile: koishi_1.Schema.boolean().default(true),
|
|
50
|
+
}),
|
|
52
51
|
koishi_1.Schema.object({
|
|
53
|
-
maxDescLength: koishi_1.Schema.number().default(200)
|
|
54
|
-
})
|
|
52
|
+
maxDescLength: koishi_1.Schema.number().default(200),
|
|
53
|
+
}),
|
|
55
54
|
koishi_1.Schema.object({
|
|
56
|
-
timeout: koishi_1.Schema.number().min(0).default(180000)
|
|
57
|
-
videoSendTimeout: koishi_1.Schema.number().min(0).default(0)
|
|
58
|
-
userAgent: koishi_1.Schema.string().default('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36')
|
|
59
|
-
})
|
|
55
|
+
timeout: koishi_1.Schema.number().min(0).default(180000),
|
|
56
|
+
videoSendTimeout: koishi_1.Schema.number().min(0).default(0),
|
|
57
|
+
userAgent: koishi_1.Schema.string().default('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'),
|
|
58
|
+
}),
|
|
60
59
|
koishi_1.Schema.object({
|
|
61
|
-
ignoreSendError: koishi_1.Schema.boolean().default(true)
|
|
62
|
-
retryTimes: koishi_1.Schema.number().min(0).default(3)
|
|
63
|
-
retryInterval: koishi_1.Schema.number().min(0).default(1000)
|
|
64
|
-
})
|
|
60
|
+
ignoreSendError: koishi_1.Schema.boolean().default(true),
|
|
61
|
+
retryTimes: koishi_1.Schema.number().min(0).default(3),
|
|
62
|
+
retryInterval: koishi_1.Schema.number().min(0).default(1000),
|
|
63
|
+
}),
|
|
65
64
|
koishi_1.Schema.object({
|
|
66
|
-
enableForward: koishi_1.Schema.boolean().default(false)
|
|
67
|
-
downloadVideoBeforeSend: koishi_1.Schema.boolean().default(false)
|
|
68
|
-
maxVideoSize: koishi_1.Schema.number().min(0).default(0)
|
|
69
|
-
downloadThreads: koishi_1.Schema.number().min(0).max(10).default(0)
|
|
70
|
-
})
|
|
65
|
+
enableForward: koishi_1.Schema.boolean().default(false),
|
|
66
|
+
downloadVideoBeforeSend: koishi_1.Schema.boolean().default(false),
|
|
67
|
+
maxVideoSize: koishi_1.Schema.number().min(0).default(0),
|
|
68
|
+
downloadThreads: koishi_1.Schema.number().min(0).max(10).default(0),
|
|
69
|
+
}),
|
|
71
70
|
koishi_1.Schema.object({
|
|
72
|
-
messageBufferDelay: koishi_1.Schema.number().min(0).default(0)
|
|
73
|
-
})
|
|
71
|
+
messageBufferDelay: koishi_1.Schema.number().min(0).default(0),
|
|
72
|
+
}),
|
|
74
73
|
koishi_1.Schema.object({
|
|
75
|
-
autoClearCacheInterval: koishi_1.Schema.number().min(0).default(0)
|
|
76
|
-
})
|
|
74
|
+
autoClearCacheInterval: koishi_1.Schema.number().min(0).default(0),
|
|
75
|
+
}),
|
|
77
76
|
]);
|
|
78
77
|
var ErrorCode;
|
|
79
78
|
(function (ErrorCode) {
|
|
@@ -166,8 +165,7 @@ const VARIABLE_MAPPING = {
|
|
|
166
165
|
'直播间ID': ['room_id', 'live.room_id', 'data.room_id', 'live.room_id', 'data.live.room_id'],
|
|
167
166
|
'直播间状态': ['status', 'live.status', 'data.status', 'room.status', 'data.live.status'],
|
|
168
167
|
'图片数量': ['count', 'data.count', 'item.count', 'images.length', 'data.images.length', 'data.item.count'],
|
|
169
|
-
'作者ID': ['userId', 'userID', 'author_id', 'data.userId', 'item.userID', 'author.mid', 'user.mid', 'data.item.userID', 'data.author_id', 'data.user.mid', 'author.id', 'uid', 'short_id', 'data.author.id']
|
|
170
|
-
'视频备用链接': ['data.video_backup', 'video_backup']
|
|
168
|
+
'作者ID': ['userId', 'userID', 'author_id', 'data.userId', 'item.userID', 'author.mid', 'user.mid', 'data.item.userID', 'data.author_id', 'data.user.mid', 'author.id', 'uid', 'short_id', 'data.author.id']
|
|
171
169
|
};
|
|
172
170
|
function getErrorInfo(code, detail) {
|
|
173
171
|
const baseMsg = exports.ErrorMessageMap[code] || exports.ErrorMessageMap[ErrorCode.UNKNOWN_ERROR];
|
|
@@ -468,11 +466,24 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
468
466
|
Object.entries(VARIABLE_MAPPING).forEach(([varName, keys]) => {
|
|
469
467
|
let value = findValueInObject(data, keys) || findValueInObject(root, keys);
|
|
470
468
|
if (varName === '图片数量' && value === undefined) {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
469
|
+
let imgCount = 0;
|
|
470
|
+
const imgSources = [
|
|
471
|
+
data.images, data.pics, data.pic_urls, data.image_list, data.imgurl,
|
|
472
|
+
root.images, root.pics, root.pic_urls, root.image_list, root.imgurl,
|
|
473
|
+
data.item?.images
|
|
474
|
+
];
|
|
475
|
+
for (const source of imgSources) {
|
|
476
|
+
if (Array.isArray(source) && source.length > 0) {
|
|
477
|
+
imgCount = source.filter(i => i && typeof i === 'string').length;
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
const cover = data.cover || data.video?.fm || data.imgurl || data.pic || data.thumbnail || data.cover_url ||
|
|
482
|
+
data.item?.cover || root.cover || data.live?.cover || data.live?.keyframe || '';
|
|
483
|
+
if (cover && imgCount > 0) {
|
|
484
|
+
imgCount = imgSources.find(source => Array.isArray(source))?.filter(i => i && typeof i === 'string' && i !== cover).length || 0;
|
|
485
|
+
}
|
|
486
|
+
value = imgCount;
|
|
476
487
|
}
|
|
477
488
|
if (value !== undefined && value !== null && value !== '' && value !== 0) {
|
|
478
489
|
stat[varName] = value;
|
|
@@ -493,9 +504,13 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
493
504
|
const title = stat['标题'] || data.note_title || data.title || data.content_title || data.video?.title ||
|
|
494
505
|
data.item?.title || root.title || data.live?.title || '无标题';
|
|
495
506
|
let author = stat['作者'] || data.author?.name || data.nickname || data.user_name || data.owner?.name ||
|
|
496
|
-
data.item?.author || root.author || data.user?.name || data.live?.author || '
|
|
497
|
-
if (typeof author === 'object'
|
|
498
|
-
author =
|
|
507
|
+
data.item?.author || root.author || data.user?.name || data.live?.author || '';
|
|
508
|
+
if (typeof author === 'object') {
|
|
509
|
+
author = '';
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
author = author || '未知作者';
|
|
513
|
+
}
|
|
499
514
|
const rawDesc = stat['简介'] || data.note_desc || data.content || data.text || data.description ||
|
|
500
515
|
data.video?.desc || data.item?.description || root.desc || root.description ||
|
|
501
516
|
data.live?.desc || (title !== '无标题' ? title : '') || '暂无简介';
|
|
@@ -513,7 +528,7 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
513
528
|
];
|
|
514
529
|
for (const source of imgSources) {
|
|
515
530
|
if (Array.isArray(source) && source.length > 0) {
|
|
516
|
-
images = source.filter(i => i && typeof i === 'string');
|
|
531
|
+
images = source.filter(i => i && typeof i === 'string' && i !== cover);
|
|
517
532
|
break;
|
|
518
533
|
}
|
|
519
534
|
}
|
|
@@ -534,6 +549,9 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
534
549
|
else {
|
|
535
550
|
delete stat['视频时长'];
|
|
536
551
|
}
|
|
552
|
+
if (stat['图片数量'] === 0) {
|
|
553
|
+
delete stat['图片数量'];
|
|
554
|
+
}
|
|
537
555
|
const sizeVal = stat['文件大小'];
|
|
538
556
|
if (sizeVal && !String(sizeVal).includes('MB')) {
|
|
539
557
|
const num = Number(sizeVal);
|
|
@@ -560,8 +578,6 @@ function parseData(rawResponse, maxDescLength) {
|
|
|
560
578
|
stat['粉丝数'] = data.followers_count;
|
|
561
579
|
if (data.ip_info_str)
|
|
562
580
|
stat['IP属地'] = data.ip_info_str;
|
|
563
|
-
if (data.video_backup)
|
|
564
|
-
stat['视频备用链接'] = data.video_backup;
|
|
565
581
|
return {
|
|
566
582
|
type: type,
|
|
567
583
|
rawData: rawResponse,
|
|
@@ -598,8 +614,7 @@ function generateFormattedText(parseData, config) {
|
|
|
598
614
|
收藏:${'${收藏数}'}
|
|
599
615
|
转发:${'${转发数}'}
|
|
600
616
|
播放:${'${播放数}'}
|
|
601
|
-
评论:${'${评论数}'}
|
|
602
|
-
视频备用链接:${'${视频备用链接}'}`;
|
|
617
|
+
评论:${'${评论数}'}`;
|
|
603
618
|
}
|
|
604
619
|
let result = format;
|
|
605
620
|
const varMatches = result.match(/\$\{([^}]+)\}/g) || [];
|
|
@@ -856,12 +871,8 @@ function apply(ctx, config) {
|
|
|
856
871
|
if (enableForward) {
|
|
857
872
|
if (item.text)
|
|
858
873
|
forwardMessages.push(buildForwardNode(session, item.text, botName));
|
|
859
|
-
if (item.cover)
|
|
874
|
+
if (item.cover && item.type !== '图集') {
|
|
860
875
|
forwardMessages.push(buildForwardNode(session, koishi_1.h.image(item.cover), botName));
|
|
861
|
-
if ((item.type === '图集' || item.type === 'image') && item.images?.length) {
|
|
862
|
-
for (const img of item.images) {
|
|
863
|
-
forwardMessages.push(buildForwardNode(session, koishi_1.h.image(img), botName));
|
|
864
|
-
}
|
|
865
876
|
}
|
|
866
877
|
if (item.video && config.showVideoFile) {
|
|
867
878
|
try {
|
|
@@ -883,22 +894,22 @@ function apply(ctx, config) {
|
|
|
883
894
|
forwardMessages.push(buildForwardNode(session, koishi_1.h.video(item.video), botName));
|
|
884
895
|
}
|
|
885
896
|
}
|
|
897
|
+
if ((item.type === '图集' || item.type === 'image') && item.images?.length) {
|
|
898
|
+
forwardMessages.push(buildForwardNode(session, `📸 图集内容(共${item.images.length}张)`, botName));
|
|
899
|
+
for (const img of item.images) {
|
|
900
|
+
forwardMessages.push(buildForwardNode(session, koishi_1.h.image(img), botName));
|
|
901
|
+
}
|
|
902
|
+
}
|
|
886
903
|
}
|
|
887
904
|
else {
|
|
888
905
|
if (item.text) {
|
|
889
906
|
await sendTimeout(session, item.text);
|
|
890
907
|
await delay(300);
|
|
891
908
|
}
|
|
892
|
-
if (item.cover) {
|
|
909
|
+
if (item.cover && item.type !== '图集') {
|
|
893
910
|
await sendTimeout(session, koishi_1.h.image(item.cover));
|
|
894
911
|
await delay(300);
|
|
895
912
|
}
|
|
896
|
-
if ((item.type === '图集' || item.type === 'image') && item.images?.length) {
|
|
897
|
-
for (const img of item.images) {
|
|
898
|
-
await sendTimeout(session, koishi_1.h.image(img));
|
|
899
|
-
await delay(200);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
913
|
if (item.video && config.showVideoFile) {
|
|
903
914
|
try {
|
|
904
915
|
await sendTimeout(session, koishi_1.h.video(item.video));
|
|
@@ -908,6 +919,14 @@ function apply(ctx, config) {
|
|
|
908
919
|
}
|
|
909
920
|
await delay(500);
|
|
910
921
|
}
|
|
922
|
+
if ((item.type === '图集' || item.type === 'image') && item.images?.length) {
|
|
923
|
+
await sendTimeout(session, `📸 图集内容(共${item.images.length}张)`);
|
|
924
|
+
await delay(300);
|
|
925
|
+
for (const img of item.images) {
|
|
926
|
+
await sendTimeout(session, koishi_1.h.image(img));
|
|
927
|
+
await delay(200);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
911
930
|
}
|
|
912
931
|
}
|
|
913
932
|
catch (e) { }
|
package/package.json
CHANGED