koishi-plugin-video-parser-all 0.3.8 → 0.3.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 +131 -122
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,95 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Config = exports.name = void 0;
|
|
7
|
+
exports.apply = apply;
|
|
8
|
+
const koishi_1 = require("koishi");
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const promises_1 = require("stream/promises");
|
|
14
|
+
const worker_threads_1 = require("worker_threads");
|
|
9
15
|
const __filename = typeof __dirname !== 'undefined'
|
|
10
|
-
?
|
|
11
|
-
:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Schema.object({
|
|
15
|
-
enable: Schema.boolean().default(true),
|
|
16
|
-
botName: Schema.string().default('视频解析机器人'),
|
|
17
|
-
showWaitingTip: Schema.boolean().default(true),
|
|
18
|
-
waitingTipText: Schema.string().default('正在解析视频,请稍候...'),
|
|
19
|
-
sameLinkInterval: Schema.number().min(0).default(180),
|
|
20
|
-
maxVideoSize: Schema.number().min(0).default(50),
|
|
21
|
-
downloadThreads: Schema.number().min(0).default(4),
|
|
16
|
+
? path_1.default.join(__dirname, 'index.js')
|
|
17
|
+
: process.cwd() + '/index.js';
|
|
18
|
+
exports.name = 'video-parser-all';
|
|
19
|
+
exports.Config = koishi_1.Schema.intersect([
|
|
20
|
+
koishi_1.Schema.object({
|
|
21
|
+
enable: koishi_1.Schema.boolean().default(true),
|
|
22
|
+
botName: koishi_1.Schema.string().default('视频解析机器人'),
|
|
23
|
+
showWaitingTip: koishi_1.Schema.boolean().default(true),
|
|
24
|
+
waitingTipText: koishi_1.Schema.string().default('正在解析视频,请稍候...'),
|
|
25
|
+
sameLinkInterval: koishi_1.Schema.number().min(0).default(180),
|
|
26
|
+
maxVideoSize: koishi_1.Schema.number().min(0).default(50),
|
|
27
|
+
downloadThreads: koishi_1.Schema.number().min(0).default(4),
|
|
22
28
|
}),
|
|
23
|
-
Schema.object({
|
|
24
|
-
platformEnable: Schema.object({
|
|
25
|
-
bilibili: Schema.boolean().default(true),
|
|
26
|
-
douyin: Schema.boolean().default(true),
|
|
27
|
-
kuaishou: Schema.boolean().default(true),
|
|
28
|
-
xigua: Schema.boolean().default(true),
|
|
29
|
-
xiaohongshu: Schema.boolean().default(true),
|
|
30
|
-
weibo: Schema.boolean().default(true),
|
|
31
|
-
toutiao: Schema.boolean().default(true),
|
|
32
|
-
pipigx: Schema.boolean().default(true),
|
|
33
|
-
pipixia: Schema.boolean().default(true),
|
|
34
|
-
zuiyou: Schema.boolean().default(true),
|
|
29
|
+
koishi_1.Schema.object({
|
|
30
|
+
platformEnable: koishi_1.Schema.object({
|
|
31
|
+
bilibili: koishi_1.Schema.boolean().default(true),
|
|
32
|
+
douyin: koishi_1.Schema.boolean().default(true),
|
|
33
|
+
kuaishou: koishi_1.Schema.boolean().default(true),
|
|
34
|
+
xigua: koishi_1.Schema.boolean().default(true),
|
|
35
|
+
xiaohongshu: koishi_1.Schema.boolean().default(true),
|
|
36
|
+
weibo: koishi_1.Schema.boolean().default(true),
|
|
37
|
+
toutiao: koishi_1.Schema.boolean().default(true),
|
|
38
|
+
pipigx: koishi_1.Schema.boolean().default(true),
|
|
39
|
+
pipixia: koishi_1.Schema.boolean().default(true),
|
|
40
|
+
zuiyou: koishi_1.Schema.boolean().default(true),
|
|
35
41
|
})
|
|
36
42
|
}),
|
|
37
|
-
Schema.object({
|
|
38
|
-
platformFormat: Schema.object({
|
|
39
|
-
bilibili: Schema.string().role('textarea').default('标题:${标题}\nUP主:${作者}\n简介:${简介}\n时长:${视频时长}\n点赞:${点赞数}\n投币:${投币数}\n收藏:${收藏数}\n转发:${转发数}'),
|
|
40
|
-
douyin: Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n点赞:${点赞数}\n收藏:${收藏数}\n转发:${转发数}'),
|
|
41
|
-
kuaishou: Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n点赞:${点赞数}\n播放:${播放数}\n转发:${转发数}'),
|
|
42
|
-
xigua: Schema.string().role('textarea').default('标题:${标题}\n播放:${播放数}\n点赞:${点赞数}\n视频大小:${视频大小}MB'),
|
|
43
|
-
xiaohongshu: Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
44
|
-
weibo: Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
45
|
-
toutiao: Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
46
|
-
pipigx: Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
47
|
-
pipixia: Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
48
|
-
zuiyou: Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
43
|
+
koishi_1.Schema.object({
|
|
44
|
+
platformFormat: koishi_1.Schema.object({
|
|
45
|
+
bilibili: koishi_1.Schema.string().role('textarea').default('标题:${标题}\nUP主:${作者}\n简介:${简介}\n时长:${视频时长}\n点赞:${点赞数}\n投币:${投币数}\n收藏:${收藏数}\n转发:${转发数}'),
|
|
46
|
+
douyin: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n点赞:${点赞数}\n收藏:${收藏数}\n转发:${转发数}'),
|
|
47
|
+
kuaishou: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n点赞:${点赞数}\n播放:${播放数}\n转发:${转发数}'),
|
|
48
|
+
xigua: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n播放:${播放数}\n点赞:${点赞数}\n视频大小:${视频大小}MB'),
|
|
49
|
+
xiaohongshu: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
50
|
+
weibo: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
51
|
+
toutiao: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
52
|
+
pipigx: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
53
|
+
pipixia: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
54
|
+
zuiyou: koishi_1.Schema.string().role('textarea').default('标题:${标题}\n作者:${作者}\n简介:${简介}'),
|
|
49
55
|
})
|
|
50
56
|
}),
|
|
51
|
-
Schema.object({
|
|
52
|
-
showImageText: Schema.boolean().default(true),
|
|
53
|
-
showVideoUrl: Schema.boolean().default(false),
|
|
54
|
-
showVideoFile: Schema.boolean().default(true),
|
|
57
|
+
koishi_1.Schema.object({
|
|
58
|
+
showImageText: koishi_1.Schema.boolean().default(true),
|
|
59
|
+
showVideoUrl: koishi_1.Schema.boolean().default(false),
|
|
60
|
+
showVideoFile: koishi_1.Schema.boolean().default(true),
|
|
55
61
|
}),
|
|
56
|
-
Schema.object({
|
|
57
|
-
maxDescLength: Schema.number().default(200),
|
|
62
|
+
koishi_1.Schema.object({
|
|
63
|
+
maxDescLength: koishi_1.Schema.number().default(200),
|
|
58
64
|
}),
|
|
59
|
-
Schema.object({
|
|
60
|
-
timeout: Schema.number().min(0).default(180000),
|
|
61
|
-
videoSendTimeout: Schema.number().min(0).default(0),
|
|
62
|
-
userAgent: 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'),
|
|
63
|
-
bilibiliAccessKey: Schema.string().default(''),
|
|
65
|
+
koishi_1.Schema.object({
|
|
66
|
+
timeout: koishi_1.Schema.number().min(0).default(180000),
|
|
67
|
+
videoSendTimeout: koishi_1.Schema.number().min(0).default(0),
|
|
68
|
+
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'),
|
|
69
|
+
bilibiliAccessKey: koishi_1.Schema.string().default(''),
|
|
64
70
|
}),
|
|
65
|
-
Schema.object({
|
|
66
|
-
ignoreSendError: Schema.boolean().default(true),
|
|
67
|
-
retryTimes: Schema.number().min(0).default(0),
|
|
68
|
-
retryInterval: Schema.number().min(0).default(0),
|
|
71
|
+
koishi_1.Schema.object({
|
|
72
|
+
ignoreSendError: koishi_1.Schema.boolean().default(true),
|
|
73
|
+
retryTimes: koishi_1.Schema.number().min(0).default(0),
|
|
74
|
+
retryInterval: koishi_1.Schema.number().min(0).default(0),
|
|
69
75
|
}),
|
|
70
|
-
Schema.object({
|
|
71
|
-
enableForward: Schema.boolean().default(false),
|
|
72
|
-
downloadVideoBeforeSend: Schema.boolean().default(false),
|
|
76
|
+
koishi_1.Schema.object({
|
|
77
|
+
enableForward: koishi_1.Schema.boolean().default(false),
|
|
78
|
+
downloadVideoBeforeSend: koishi_1.Schema.boolean().default(false),
|
|
73
79
|
}),
|
|
74
|
-
Schema.object({
|
|
75
|
-
messageBufferDelay: Schema.number().min(0).default(0),
|
|
80
|
+
koishi_1.Schema.object({
|
|
81
|
+
messageBufferDelay: koishi_1.Schema.number().min(0).default(0),
|
|
76
82
|
}),
|
|
77
|
-
Schema.object({
|
|
78
|
-
autoClearCacheInterval: Schema.number().min(0).default(0),
|
|
83
|
+
koishi_1.Schema.object({
|
|
84
|
+
autoClearCacheInterval: koishi_1.Schema.number().min(0).default(0),
|
|
79
85
|
}),
|
|
80
86
|
]);
|
|
81
|
-
if (!isMainThread) {
|
|
82
|
-
const workerDataTyped = workerData;
|
|
87
|
+
if (!worker_threads_1.isMainThread) {
|
|
88
|
+
const workerDataTyped = worker_threads_1.workerData;
|
|
83
89
|
const { url, filePath, maxSize } = workerDataTyped;
|
|
84
90
|
(async () => {
|
|
85
91
|
try {
|
|
86
92
|
if (url.endsWith('.m4a') || url.endsWith('.mp3')) {
|
|
87
|
-
parentPort?.postMessage({ success: false, error: '不支持音频' });
|
|
93
|
+
worker_threads_1.parentPort?.postMessage({ success: false, error: '不支持音频' });
|
|
88
94
|
return;
|
|
89
95
|
}
|
|
90
96
|
let downloadedSize = 0;
|
|
91
97
|
const maxSizeBytes = maxSize * 1024 * 1024;
|
|
92
|
-
const response = await
|
|
98
|
+
const response = await (0, axios_1.default)({
|
|
93
99
|
url,
|
|
94
100
|
method: 'GET',
|
|
95
101
|
responseType: 'stream',
|
|
@@ -101,25 +107,25 @@ if (!isMainThread) {
|
|
|
101
107
|
if (maxSize > 0 && response.headers['content-length']) {
|
|
102
108
|
const contentLength = parseInt(response.headers['content-length']);
|
|
103
109
|
if (contentLength > maxSizeBytes) {
|
|
104
|
-
parentPort?.postMessage({ success: false, error: `视频大小超过限制(${maxSize}MB)` });
|
|
110
|
+
worker_threads_1.parentPort?.postMessage({ success: false, error: `视频大小超过限制(${maxSize}MB)` });
|
|
105
111
|
return;
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
|
-
const writeStream =
|
|
114
|
+
const writeStream = fs_1.default.createWriteStream(filePath);
|
|
109
115
|
response.data.on('data', (chunk) => {
|
|
110
116
|
downloadedSize += chunk.length;
|
|
111
117
|
if (maxSize > 0 && downloadedSize > maxSizeBytes) {
|
|
112
118
|
response.data.destroy();
|
|
113
119
|
writeStream.destroy();
|
|
114
|
-
|
|
115
|
-
parentPort?.postMessage({ success: false, error: `视频大小超过限制(${maxSize}MB)` });
|
|
120
|
+
fs_1.default.unlinkSync(filePath);
|
|
121
|
+
worker_threads_1.parentPort?.postMessage({ success: false, error: `视频大小超过限制(${maxSize}MB)` });
|
|
116
122
|
}
|
|
117
123
|
});
|
|
118
|
-
await pipeline(response.data, writeStream);
|
|
119
|
-
parentPort?.postMessage({ success: true, filePath });
|
|
124
|
+
await (0, promises_1.pipeline)(response.data, writeStream);
|
|
125
|
+
worker_threads_1.parentPort?.postMessage({ success: true, filePath });
|
|
120
126
|
}
|
|
121
127
|
catch (error) {
|
|
122
|
-
parentPort?.postMessage({ success: false, error: error.message });
|
|
128
|
+
worker_threads_1.parentPort?.postMessage({ success: false, error: error.message });
|
|
123
129
|
}
|
|
124
130
|
})();
|
|
125
131
|
}
|
|
@@ -186,7 +192,7 @@ async function fetch_bilibili_official_info(id, userAgent) {
|
|
|
186
192
|
return null;
|
|
187
193
|
}
|
|
188
194
|
try {
|
|
189
|
-
const response = await
|
|
195
|
+
const response = await axios_1.default.get(url, {
|
|
190
196
|
headers: { 'User-Agent': userAgent },
|
|
191
197
|
timeout: 10000
|
|
192
198
|
});
|
|
@@ -199,7 +205,7 @@ async function fetch_bilibili_official_info(id, userAgent) {
|
|
|
199
205
|
async function get_bilibili_play_url(bvid, cid, userAgent) {
|
|
200
206
|
try {
|
|
201
207
|
const playUrl = `https://api.bilibili.com/x/player/playurl?fnval=80&cid=${cid}&bvid=${bvid}`;
|
|
202
|
-
const playData = await
|
|
208
|
+
const playData = await axios_1.default.get(playUrl, {
|
|
203
209
|
headers: {
|
|
204
210
|
"User-Agent": userAgent,
|
|
205
211
|
"Referer": "https://www.bilibili.com/"
|
|
@@ -430,7 +436,7 @@ async function resolveShortUrl(url) {
|
|
|
430
436
|
if (url.startsWith('BV') || url.startsWith('av') || url.startsWith('AV'))
|
|
431
437
|
return url;
|
|
432
438
|
try {
|
|
433
|
-
const res = await
|
|
439
|
+
const res = await axios_1.default.head(url, {
|
|
434
440
|
timeout: 5000,
|
|
435
441
|
maxRedirects: 5,
|
|
436
442
|
headers: {
|
|
@@ -445,7 +451,7 @@ async function resolveShortUrl(url) {
|
|
|
445
451
|
}
|
|
446
452
|
async function shortUrl(url) {
|
|
447
453
|
try {
|
|
448
|
-
const res = await
|
|
454
|
+
const res = await axios_1.default.get('https://api.oick.cn/dwz/api.php', { params: { url }, timeout: 5000 });
|
|
449
455
|
if (res.data.code === 200)
|
|
450
456
|
return res.data.short_url;
|
|
451
457
|
}
|
|
@@ -454,15 +460,15 @@ async function shortUrl(url) {
|
|
|
454
460
|
}
|
|
455
461
|
async function downloadVideoWithThreads(url, filename, maxSize, threads, userAgent) {
|
|
456
462
|
return new Promise((resolve, reject) => {
|
|
457
|
-
const dir =
|
|
458
|
-
if (!
|
|
459
|
-
|
|
460
|
-
const filePath =
|
|
463
|
+
const dir = path_1.default.join(process.cwd(), 'temp_videos');
|
|
464
|
+
if (!fs_1.default.existsSync(dir))
|
|
465
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
466
|
+
const filePath = path_1.default.join(dir, `${filename}.mp4`);
|
|
461
467
|
const workerData = { url, filePath, maxSize, userAgent };
|
|
462
468
|
if (threads > 0) {
|
|
463
469
|
workerData.threads = threads;
|
|
464
470
|
}
|
|
465
|
-
const worker = new Worker(__filename, { workerData });
|
|
471
|
+
const worker = new worker_threads_1.Worker(__filename, { workerData });
|
|
466
472
|
worker.on('message', (result) => {
|
|
467
473
|
if (result.success && result.filePath) {
|
|
468
474
|
resolve(result.filePath);
|
|
@@ -558,11 +564,11 @@ function clearAllCache() {
|
|
|
558
564
|
processed.clear();
|
|
559
565
|
linkBuffer.forEach(buf => clearTimeout(buf.timer));
|
|
560
566
|
linkBuffer.clear();
|
|
561
|
-
const tempDir =
|
|
562
|
-
if (
|
|
563
|
-
|
|
567
|
+
const tempDir = path_1.default.join(process.cwd(), 'temp_videos');
|
|
568
|
+
if (fs_1.default.existsSync(tempDir)) {
|
|
569
|
+
fs_1.default.readdirSync(tempDir).forEach(file => {
|
|
564
570
|
try {
|
|
565
|
-
|
|
571
|
+
fs_1.default.unlinkSync(path_1.default.join(tempDir, file));
|
|
566
572
|
}
|
|
567
573
|
catch (error) { }
|
|
568
574
|
});
|
|
@@ -576,16 +582,16 @@ function buildForwardNode(session, content, botName) {
|
|
|
576
582
|
data: {
|
|
577
583
|
name: botName.substring(0, 15),
|
|
578
584
|
uin: session.selfId.toString(),
|
|
579
|
-
content: Array.isArray(content) ? content : [h.text(content)],
|
|
585
|
+
content: Array.isArray(content) ? content : [koishi_1.h.text(content)],
|
|
580
586
|
time: Math.floor(Date.now() / 1000)
|
|
581
587
|
}
|
|
582
588
|
};
|
|
583
589
|
}
|
|
584
|
-
|
|
585
|
-
if (!isMainThread)
|
|
590
|
+
function apply(ctx, config) {
|
|
591
|
+
if (!worker_threads_1.isMainThread)
|
|
586
592
|
return;
|
|
587
593
|
clearAllCache();
|
|
588
|
-
const http =
|
|
594
|
+
const http = axios_1.default.create({
|
|
589
595
|
timeout: config.timeout,
|
|
590
596
|
headers: { 'User-Agent': config.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' }
|
|
591
597
|
});
|
|
@@ -795,13 +801,16 @@ export function apply(ctx, config) {
|
|
|
795
801
|
}
|
|
796
802
|
return { data: null, msg: '西瓜视频解析失败' };
|
|
797
803
|
}
|
|
804
|
+
// 修复:确保 currentPlatform 不为 null
|
|
805
|
+
const currentPlatform = platform;
|
|
798
806
|
const nonKuaishouPlatforms = ['xiaohongshu', 'weibo', 'toutiao', 'pipigx', 'pipixia', 'zuiyou'];
|
|
799
|
-
if (nonKuaishouPlatforms.includes(
|
|
807
|
+
if (nonKuaishouPlatforms.includes(currentPlatform)) {
|
|
800
808
|
for (let retry = 0; retry <= config.retryTimes; retry++) {
|
|
801
809
|
try {
|
|
802
810
|
const res = await http.get(API_CONFIG.universal, { params: { url: realUrl } });
|
|
803
811
|
if ((res.data.code === 200 || res.data.code === 0) && res.data.data) {
|
|
804
|
-
|
|
812
|
+
// currentPlatform 已经被断言为非 null,安全传递给 parseData
|
|
813
|
+
const parseResult = parseData(res.data.data, config.maxDescLength, currentPlatform);
|
|
805
814
|
return { data: parseResult, msg: '解析成功' };
|
|
806
815
|
}
|
|
807
816
|
else if (res.data.code === 201) {
|
|
@@ -815,7 +824,7 @@ export function apply(ctx, config) {
|
|
|
815
824
|
}
|
|
816
825
|
}
|
|
817
826
|
}
|
|
818
|
-
const platformApis = API_CONFIG.platform[
|
|
827
|
+
const platformApis = API_CONFIG.platform[currentPlatform] || [];
|
|
819
828
|
for (let apiIndex = 0; apiIndex < platformApis.length; apiIndex++) {
|
|
820
829
|
const apiUrl = platformApis[apiIndex];
|
|
821
830
|
for (let retry = 0; retry <= config.retryTimes; retry++) {
|
|
@@ -824,17 +833,17 @@ export function apply(ctx, config) {
|
|
|
824
833
|
let shouldContinue = false;
|
|
825
834
|
if ((res.data.code === 200 || res.data.code === 0)) {
|
|
826
835
|
let parseResult = null;
|
|
827
|
-
if (
|
|
836
|
+
if (currentPlatform === 'kuaishou') {
|
|
828
837
|
if (res.data.image && !res.data.data) {
|
|
829
838
|
parseResult = parseData({
|
|
830
839
|
title: res.data.data?.title || '快手图集',
|
|
831
840
|
author: res.data.data?.author || '未知作者',
|
|
832
841
|
images: res.data.image,
|
|
833
842
|
type: 'image'
|
|
834
|
-
}, config.maxDescLength,
|
|
843
|
+
}, config.maxDescLength, currentPlatform);
|
|
835
844
|
}
|
|
836
845
|
else if (res.data.data) {
|
|
837
|
-
parseResult = parseData(res.data.data, config.maxDescLength,
|
|
846
|
+
parseResult = parseData(res.data.data, config.maxDescLength, currentPlatform);
|
|
838
847
|
}
|
|
839
848
|
else {
|
|
840
849
|
shouldContinue = true;
|
|
@@ -842,7 +851,7 @@ export function apply(ctx, config) {
|
|
|
842
851
|
}
|
|
843
852
|
else {
|
|
844
853
|
if (res.data.data) {
|
|
845
|
-
parseResult = parseData(res.data.data, config.maxDescLength,
|
|
854
|
+
parseResult = parseData(res.data.data, config.maxDescLength, currentPlatform);
|
|
846
855
|
}
|
|
847
856
|
else {
|
|
848
857
|
shouldContinue = true;
|
|
@@ -870,7 +879,7 @@ export function apply(ctx, config) {
|
|
|
870
879
|
return { data: null, msg: '解析失败,请稍后重试' };
|
|
871
880
|
}
|
|
872
881
|
async function processSingleUrl(session, url) {
|
|
873
|
-
const hash =
|
|
882
|
+
const hash = crypto_1.default.createHash('md5').update(url).digest('hex');
|
|
874
883
|
const now = Date.now();
|
|
875
884
|
if (processed.get(hash) && now - processed.get(hash) < config.sameLinkInterval * 1000) {
|
|
876
885
|
return { data: null, msg: '请勿重复解析' };
|
|
@@ -953,27 +962,27 @@ export function apply(ctx, config) {
|
|
|
953
962
|
forwardMessages.push(buildForwardNode(session, item.text, botName));
|
|
954
963
|
}
|
|
955
964
|
if (item.cover && forwardMessages.length < 100) {
|
|
956
|
-
forwardMessages.push(buildForwardNode(session, h.image(item.cover), botName));
|
|
965
|
+
forwardMessages.push(buildForwardNode(session, koishi_1.h.image(item.cover), botName));
|
|
957
966
|
}
|
|
958
967
|
if (item.type === 'image' && item.images?.length) {
|
|
959
968
|
for (let i = 0; i < item.images.length && forwardMessages.length < 100; i++) {
|
|
960
|
-
forwardMessages.push(buildForwardNode(session, h.image(item.images[i]), botName));
|
|
969
|
+
forwardMessages.push(buildForwardNode(session, koishi_1.h.image(item.images[i]), botName));
|
|
961
970
|
}
|
|
962
971
|
}
|
|
963
972
|
if (item.video && config.showVideoFile && forwardMessages.length < 100) {
|
|
964
973
|
let videoElem;
|
|
965
974
|
if (config.downloadVideoBeforeSend) {
|
|
966
975
|
try {
|
|
967
|
-
const filename =
|
|
976
|
+
const filename = crypto_1.default.createHash('md5').update(item.video).digest('hex');
|
|
968
977
|
const filePath = await downloadVideoWithThreads(item.video, filename, config.maxVideoSize, config.downloadThreads, config.userAgent);
|
|
969
|
-
videoElem = h.file(filePath);
|
|
978
|
+
videoElem = koishi_1.h.file(filePath);
|
|
970
979
|
}
|
|
971
980
|
catch (error) {
|
|
972
|
-
videoElem = h.video(item.video);
|
|
981
|
+
videoElem = koishi_1.h.video(item.video);
|
|
973
982
|
}
|
|
974
983
|
}
|
|
975
984
|
else {
|
|
976
|
-
videoElem = h.video(item.video);
|
|
985
|
+
videoElem = koishi_1.h.video(item.video);
|
|
977
986
|
}
|
|
978
987
|
forwardMessages.push(buildForwardNode(session, videoElem, botName));
|
|
979
988
|
}
|
|
@@ -988,28 +997,28 @@ export function apply(ctx, config) {
|
|
|
988
997
|
await delay(300);
|
|
989
998
|
}
|
|
990
999
|
if (item.type === 'image' && item.images?.length) {
|
|
991
|
-
const imgMsg = h('message', ...item.images.map(url => h.image(url)));
|
|
1000
|
+
const imgMsg = (0, koishi_1.h)('message', ...item.images.map((url) => koishi_1.h.image(url)));
|
|
992
1001
|
await sendTimeout(session, imgMsg);
|
|
993
1002
|
}
|
|
994
1003
|
else {
|
|
995
1004
|
if (item.cover) {
|
|
996
|
-
await sendTimeout(session, h.image(item.cover));
|
|
1005
|
+
await sendTimeout(session, koishi_1.h.image(item.cover));
|
|
997
1006
|
await delay(300);
|
|
998
1007
|
}
|
|
999
1008
|
if (item.video && config.showVideoFile) {
|
|
1000
1009
|
let videoElem;
|
|
1001
1010
|
if (config.downloadVideoBeforeSend) {
|
|
1002
1011
|
try {
|
|
1003
|
-
const filename =
|
|
1012
|
+
const filename = crypto_1.default.createHash('md5').update(item.video).digest('hex');
|
|
1004
1013
|
const filePath = await downloadVideoWithThreads(item.video, filename, config.maxVideoSize, config.downloadThreads, config.userAgent);
|
|
1005
|
-
videoElem = h.file(filePath);
|
|
1014
|
+
videoElem = koishi_1.h.file(filePath);
|
|
1006
1015
|
}
|
|
1007
1016
|
catch (error) {
|
|
1008
|
-
videoElem = h.video(item.video);
|
|
1017
|
+
videoElem = koishi_1.h.video(item.video);
|
|
1009
1018
|
}
|
|
1010
1019
|
}
|
|
1011
1020
|
else {
|
|
1012
|
-
videoElem = h.video(item.video);
|
|
1021
|
+
videoElem = koishi_1.h.video(item.video);
|
|
1013
1022
|
}
|
|
1014
1023
|
await sendTimeout(session, videoElem);
|
|
1015
1024
|
}
|
|
@@ -1029,7 +1038,7 @@ export function apply(ctx, config) {
|
|
|
1029
1038
|
if (enableForward && forwardMessages.length) {
|
|
1030
1039
|
try {
|
|
1031
1040
|
const safeForwardMessages = forwardMessages.slice(0, 100);
|
|
1032
|
-
const forwardMsg = h('message', { forward: true }, safeForwardMessages);
|
|
1041
|
+
const forwardMsg = (0, koishi_1.h)('message', { forward: true }, safeForwardMessages);
|
|
1033
1042
|
await sendTimeout(session, forwardMsg);
|
|
1034
1043
|
}
|
|
1035
1044
|
catch (error) {
|
|
@@ -1047,7 +1056,7 @@ export function apply(ctx, config) {
|
|
|
1047
1056
|
let urls = extractUrl(content);
|
|
1048
1057
|
if (urls.length === 0 && hasPlatformKeyword(content)) {
|
|
1049
1058
|
const allLinks = content.match(/https?:\/\/[^\s\"\'\>\]]+/gi) || [];
|
|
1050
|
-
urls = allLinks.filter(u => getPlatformType(u));
|
|
1059
|
+
urls = allLinks.filter((u) => getPlatformType(u));
|
|
1051
1060
|
}
|
|
1052
1061
|
if (urls.length === 0)
|
|
1053
1062
|
return;
|
|
@@ -1080,7 +1089,7 @@ export function apply(ctx, config) {
|
|
|
1080
1089
|
let urls = extractUrl(url);
|
|
1081
1090
|
if (urls.length === 0 && hasPlatformKeyword(url)) {
|
|
1082
1091
|
const allLinks = url.match(/https?:\/\/[^\s\"\'\>\]]+/gi) || [];
|
|
1083
|
-
urls = allLinks.filter(u => getPlatformType(u));
|
|
1092
|
+
urls = allLinks.filter((u) => getPlatformType(u));
|
|
1084
1093
|
}
|
|
1085
1094
|
if (urls.length === 0)
|
|
1086
1095
|
return '不支持该链接';
|
|
@@ -1099,15 +1108,15 @@ export function apply(ctx, config) {
|
|
|
1099
1108
|
});
|
|
1100
1109
|
}, 3600000);
|
|
1101
1110
|
setInterval(() => {
|
|
1102
|
-
const tempDir =
|
|
1103
|
-
if (!
|
|
1111
|
+
const tempDir = path_1.default.join(process.cwd(), 'temp_videos');
|
|
1112
|
+
if (!fs_1.default.existsSync(tempDir))
|
|
1104
1113
|
return;
|
|
1105
1114
|
const now = Date.now();
|
|
1106
|
-
|
|
1115
|
+
fs_1.default.readdirSync(tempDir).forEach(file => {
|
|
1107
1116
|
try {
|
|
1108
|
-
const stat =
|
|
1117
|
+
const stat = fs_1.default.statSync(path_1.default.join(tempDir, file));
|
|
1109
1118
|
if (now - stat.mtimeMs > 3600000) {
|
|
1110
|
-
|
|
1119
|
+
fs_1.default.unlinkSync(path_1.default.join(tempDir, file));
|
|
1111
1120
|
}
|
|
1112
1121
|
}
|
|
1113
1122
|
catch (error) { }
|
package/package.json
CHANGED