koishi-plugin-video-parser-all 0.9.9 → 1.0.0
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 +9 -8
- package/package.json +1 -1
- package/readme.md +11 -4
package/lib/index.js
CHANGED
|
@@ -28,7 +28,7 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
28
28
|
maxDescLength: koishi_1.Schema.number().default(200).description('简介内容最大长度(字符),超出自动截断'),
|
|
29
29
|
videoDownloadTimeout: koishi_1.Schema.number().default(120000).description('视频下载超时(毫秒)'),
|
|
30
30
|
tempDir: koishi_1.Schema.string().default('./temp_videos').description('临时视频存储目录'),
|
|
31
|
-
maxVideoSize: koishi_1.Schema.number().default(
|
|
31
|
+
maxVideoSize: koishi_1.Schema.number().min(0).step(1).default(0).description('最大下载视频大小(MB),0 为不限制大小'),
|
|
32
32
|
}).description('内容显示设置'),
|
|
33
33
|
koishi_1.Schema.object({
|
|
34
34
|
timeout: koishi_1.Schema.number().min(0).default(180000).description('API 请求超时(毫秒)'),
|
|
@@ -208,7 +208,7 @@ function formatDuration(seconds) {
|
|
|
208
208
|
const s = Math.floor(seconds % 60);
|
|
209
209
|
if (h > 0)
|
|
210
210
|
return `${h}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
|
|
211
|
-
return `${m}:${s.toString().padStart(2, '0')}`;
|
|
211
|
+
return `${m}:${s.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
|
|
212
212
|
}
|
|
213
213
|
function formatPublishTime(ms) {
|
|
214
214
|
if (!ms)
|
|
@@ -362,7 +362,7 @@ function buildForwardNode(session, content, botName) {
|
|
|
362
362
|
}
|
|
363
363
|
const urlCache = new Map();
|
|
364
364
|
const CACHE_TTL = 10 * 60 * 1000;
|
|
365
|
-
async function downloadVideoFile(videoUrl, tempDir, timeout,
|
|
365
|
+
async function downloadVideoFile(videoUrl, tempDir, timeout, maxSizeMB) {
|
|
366
366
|
await promises_1.default.mkdir(tempDir, { recursive: true });
|
|
367
367
|
const fileName = `video_${Date.now()}_${Math.random().toString(36).substring(2, 8)}.mp4`;
|
|
368
368
|
const filePath = path_1.default.join(tempDir, fileName);
|
|
@@ -376,20 +376,21 @@ async function downloadVideoFile(videoUrl, tempDir, timeout, maxSize) {
|
|
|
376
376
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
377
377
|
}
|
|
378
378
|
});
|
|
379
|
+
const maxSizeBytes = maxSizeMB * 1024 * 1024;
|
|
379
380
|
const contentLength = Number(response.headers['content-length'] || 0);
|
|
380
|
-
if (contentLength >
|
|
381
|
+
if (maxSizeMB > 0 && contentLength > maxSizeBytes) {
|
|
381
382
|
writer.destroy();
|
|
382
383
|
await promises_1.default.unlink(filePath).catch(() => { });
|
|
383
|
-
throw new Error(`视频文件过大(${Math.round(contentLength / 1024 / 1024)}MB),超过限制(${
|
|
384
|
+
throw new Error(`视频文件过大(${Math.round(contentLength / 1024 / 1024)}MB),超过限制(${maxSizeMB}MB)`);
|
|
384
385
|
}
|
|
385
386
|
let downloadedSize = 0;
|
|
386
387
|
response.data.on('data', (chunk) => {
|
|
387
388
|
downloadedSize += chunk.length;
|
|
388
|
-
if (downloadedSize >
|
|
389
|
+
if (maxSizeMB > 0 && downloadedSize > maxSizeBytes) {
|
|
389
390
|
response.data.destroy();
|
|
390
391
|
writer.destroy();
|
|
391
392
|
promises_1.default.unlink(filePath).catch(() => { });
|
|
392
|
-
throw new Error(`视频文件过大,超过限制(${
|
|
393
|
+
throw new Error(`视频文件过大,超过限制(${maxSizeMB}MB)`);
|
|
393
394
|
}
|
|
394
395
|
});
|
|
395
396
|
await (0, promises_2.pipeline)(response.data, writer);
|
|
@@ -521,7 +522,7 @@ function apply(ctx, config) {
|
|
|
521
522
|
debugLog('ERROR', `直接发送URL失败,开始下载视频: ${getErrorMessage(err)}`);
|
|
522
523
|
let tempFilePath = null;
|
|
523
524
|
try {
|
|
524
|
-
tempFilePath = await downloadVideoFile(videoUrl, config.tempDir || './temp_videos', config.videoDownloadTimeout || 120000, config.maxVideoSize ||
|
|
525
|
+
tempFilePath = await downloadVideoFile(videoUrl, config.tempDir || './temp_videos', config.videoDownloadTimeout || 120000, config.maxVideoSize || 0);
|
|
525
526
|
const localFile = `file://${path_1.default.resolve(tempFilePath)}`;
|
|
526
527
|
debugLog('INFO', `视频下载完成,发送本地文件: ${localFile}`);
|
|
527
528
|
return await sendWithTimeout(session, koishi_1.h.video(localFile));
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -5,24 +5,28 @@
|
|
|
5
5
|
### 中文
|
|
6
6
|
这是一个为 Koishi 机器人框架开发的**全平台视频/图集解析插件**,使用统一API接口,支持自动识别并解析抖音、快手、B站、小红书、微博、YouTube、TikTok、剪映、AcFun、知乎、虎牙等20+主流平台的短视频/图集/实况链接。核心特性:
|
|
7
7
|
- 🌐 统一API解析,覆盖20+热门平台,无需繁琐配置
|
|
8
|
-
- 🤖 自动识别链接来源,即丢即用,并支持解析 XML 卡片消息中的链接(如 QQ/OneBot 平台的分享卡片)
|
|
8
|
+
- 🤖 自动识别链接来源,即丢即用,并支持解析 XML/JSON 卡片消息中的链接(如 QQ/OneBot 平台的分享卡片)
|
|
9
9
|
- 🎨 完全自定义的解析结果格式,支持多项变量替换,变量无值自动隐藏行
|
|
10
10
|
- 🐛 内置Debug调试模式,可详细记录所有操作与API交互日志
|
|
11
11
|
- 📤 支持OneBot平台消息合并转发,优化多图文展示体验
|
|
12
12
|
- 💬 所有提示文案均可自定义,适配多语言场景
|
|
13
13
|
- 🔁 消息发送支持自动重试,与API重试配置联动,增强稳定性
|
|
14
14
|
- 🚀 内置内存缓存,避免短时间内重复解析同一链接;并发控制,防止资源耗尽
|
|
15
|
+
- ⚡ 优先直接发送视频URL,失败自动降级为本地文件发送,大幅提升性能
|
|
16
|
+
- 🛡️ 可选视频大小限制,防止超大文件占满服务器磁盘;自动清理所有临时文件
|
|
15
17
|
|
|
16
18
|
### English
|
|
17
19
|
This is a **multi-platform video/image parsing plugin** developed for the Koishi bot framework, using a unified API interface to automatically recognize and parse short video/image/live photo links from 20+ mainstream platforms such as Douyin, Kuaishou, Bilibili, Xiaohongshu, Weibo, YouTube, TikTok, Jianying, AcFun, Zhihu, Huya and more. Core features:
|
|
18
20
|
- 🌐 Unified API parsing, covering 20+ popular platforms without complex configuration
|
|
19
|
-
- 🤖 Auto-detection of link sources, drop & go, and support for extracting links from XML card messages (e.g., share cards on QQ/OneBot)
|
|
21
|
+
- 🤖 Auto-detection of link sources, drop & go, and support for extracting links from XML/JSON card messages (e.g., share cards on QQ/OneBot)
|
|
20
22
|
- 🎨 Fully customizable parsing result format with variable substitutions, empty variables hide the line automatically
|
|
21
23
|
- 🐛 Built-in Debug mode, recording detailed operations and API interaction logs
|
|
22
24
|
- 📤 Support OneBot message forwarding for better image/video display
|
|
23
25
|
- 💬 All prompt texts are customizable for multilingual scenarios
|
|
24
26
|
- 🔁 Message sending supports automatic retries, linked with API retry configuration for improved stability
|
|
25
27
|
- 🚀 Built-in memory cache to avoid repeated parsing of the same URL; concurrency control to prevent resource exhaustion
|
|
28
|
+
- ⚡ Priority to send video URL directly, automatically downgrade to local file sending on failure, greatly improving performance
|
|
29
|
+
- 🛡️ Optional video size limit to prevent oversized files from filling up server disk; automatic cleanup of all temporary files
|
|
26
30
|
|
|
27
31
|
## 项目仓库 (Repository)
|
|
28
32
|
- GitHub: `https://github.com/Minecraft-1314/koishi-plugin-video-parser-all`
|
|
@@ -55,13 +59,16 @@ This is a **multi-platform video/image parsing plugin** developed for the Koishi
|
|
|
55
59
|
| `showImageText` | boolean | true | 是否发送解析后的文字内容 |
|
|
56
60
|
| `showVideoFile` | boolean | true | 是否发送视频文件(关闭则只发送视频链接) |
|
|
57
61
|
| `maxDescLength` | number | 200 | 简介内容最大长度(字符),超出自动截断 |
|
|
62
|
+
| `videoDownloadTimeout` | number | 120000 | 视频下载超时(毫秒) |
|
|
63
|
+
| `tempDir` | string | `./temp_videos` | 临时视频存储目录 |
|
|
64
|
+
| `maxVideoSize` | number | 0 | 最大下载视频大小(MB),0 为不限制大小 |
|
|
58
65
|
|
|
59
66
|
### 网络与 API 设置
|
|
60
67
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
61
68
|
|--------|------|--------|------|
|
|
62
69
|
| `timeout` | number | 180000 | API 请求超时时间(毫秒) |
|
|
63
70
|
| `videoSendTimeout` | number | 60000 | 视频消息发送超时时间(毫秒,0 为不限制) |
|
|
64
|
-
| `userAgent` | string |
|
|
71
|
+
| `userAgent` | string | `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36` | API 请求使用的 User-Agent |
|
|
65
72
|
|
|
66
73
|
### 错误与重试设置
|
|
67
74
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
@@ -82,7 +89,7 @@ This is a **multi-platform video/image parsing plugin** developed for the Koishi
|
|
|
82
89
|
| `unsupportedPlatformText` | string | 不支持该平台链接 | 不支持的平台提示 |
|
|
83
90
|
| `invalidLinkText` | string | 无效的视频链接 | 无效链接提示(parse 指令) |
|
|
84
91
|
| `parseErrorPrefix` | string | ❌ 解析失败: | 解析失败消息前缀 |
|
|
85
|
-
| `parseErrorItemFormat` | string |
|
|
92
|
+
| `parseErrorItemFormat` | string | `【${url}】: ${msg}` | 每条解析失败的展示格式,可用 ${url}(链接)和 ${msg}(错误信息) |
|
|
86
93
|
|
|
87
94
|
## 支持的变量 (Supported Variables)
|
|
88
95
|
在 `unifiedMessageFormat` 中可使用以下变量进行自定义格式化,某行所有变量均为空(或为"0")时该行不显示:
|