koishi-plugin-video-parser-all 0.8.7 → 0.8.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.d.ts +0 -2
- package/lib/index.js +31 -24
- package/package.json +1 -1
- package/readme.md +30 -50
package/lib/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export declare const Config: Schema<{
|
|
|
10
10
|
} & {
|
|
11
11
|
showImageText?: boolean | null | undefined;
|
|
12
12
|
showVideoFile?: boolean | null | undefined;
|
|
13
|
-
sendLivePhotoVideos?: boolean | null | undefined;
|
|
14
13
|
maxDescLength?: number | null | undefined;
|
|
15
14
|
} & {
|
|
16
15
|
timeout?: number | null | undefined;
|
|
@@ -38,7 +37,6 @@ export declare const Config: Schema<{
|
|
|
38
37
|
} & {
|
|
39
38
|
showImageText: boolean;
|
|
40
39
|
showVideoFile: boolean;
|
|
41
|
-
sendLivePhotoVideos: boolean;
|
|
42
40
|
maxDescLength: number;
|
|
43
41
|
} & {
|
|
44
42
|
timeout: number;
|
package/lib/index.js
CHANGED
|
@@ -21,7 +21,6 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
21
21
|
koishi_1.Schema.object({
|
|
22
22
|
showImageText: koishi_1.Schema.boolean().default(true).description('是否发送解析后的文字内容'),
|
|
23
23
|
showVideoFile: koishi_1.Schema.boolean().default(true).description('是否发送视频文件(关闭则只发送视频链接)'),
|
|
24
|
-
sendLivePhotoVideos: koishi_1.Schema.boolean().default(true).description('发送实况图集时是否附带短视频'),
|
|
25
24
|
maxDescLength: koishi_1.Schema.number().default(200).description('简介内容最大长度(字符),超出自动截断'),
|
|
26
25
|
}).description('内容显示设置'),
|
|
27
26
|
koishi_1.Schema.object({
|
|
@@ -136,7 +135,7 @@ async function resolveShortUrl(url) {
|
|
|
136
135
|
}
|
|
137
136
|
function formatDuration(seconds) {
|
|
138
137
|
if (!seconds || seconds <= 0)
|
|
139
|
-
return '
|
|
138
|
+
return '';
|
|
140
139
|
const h = Math.floor(seconds / 3600);
|
|
141
140
|
const m = Math.floor((seconds % 3600) / 60);
|
|
142
141
|
const s = Math.floor(seconds % 60);
|
|
@@ -240,6 +239,7 @@ function parseApiResponse(raw, maxDescLen) {
|
|
|
240
239
|
};
|
|
241
240
|
}
|
|
242
241
|
function generateFormattedText(p, format) {
|
|
242
|
+
const imageCount = p.images.length || p.live_photo.length;
|
|
243
243
|
const vars = {
|
|
244
244
|
'标题': p.title,
|
|
245
245
|
'作者': p.author,
|
|
@@ -251,18 +251,37 @@ function generateFormattedText(p, format) {
|
|
|
251
251
|
'播放数': String(p.play),
|
|
252
252
|
'评论数': String(p.comment),
|
|
253
253
|
'发布时间': p.publishTime ? formatPublishTime(p.publishTime) : '',
|
|
254
|
-
'图片数量': String(
|
|
254
|
+
'图片数量': String(imageCount),
|
|
255
255
|
'作者ID': p.uid,
|
|
256
256
|
'视频链接': p.video,
|
|
257
257
|
'封面': p.cover,
|
|
258
258
|
'音乐作者': p.music.author || '',
|
|
259
259
|
'音乐标题': p.music.title || '',
|
|
260
260
|
};
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
261
|
+
const lines = format.split('\n');
|
|
262
|
+
const resultLines = [];
|
|
263
|
+
for (const line of lines) {
|
|
264
|
+
const varMatches = line.match(/\$\{([^}]+)\}/g);
|
|
265
|
+
if (varMatches) {
|
|
266
|
+
let allEmpty = true;
|
|
267
|
+
for (const match of varMatches) {
|
|
268
|
+
const varName = match.replace(/\$\{|\}/g, '');
|
|
269
|
+
const val = vars[varName];
|
|
270
|
+
if (val !== undefined && val !== '') {
|
|
271
|
+
allEmpty = false;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (allEmpty)
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
let newLine = line;
|
|
279
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
280
|
+
newLine = newLine.replace(new RegExp(`\\$\\{${key}\\}`, 'g'), value);
|
|
281
|
+
}
|
|
282
|
+
resultLines.push(newLine);
|
|
264
283
|
}
|
|
265
|
-
return
|
|
284
|
+
return resultLines.join('\n').trim();
|
|
266
285
|
}
|
|
267
286
|
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
268
287
|
function buildForwardNode(session, content, botName) {
|
|
@@ -419,28 +438,16 @@ function apply(ctx, config) {
|
|
|
419
438
|
}
|
|
420
439
|
}
|
|
421
440
|
if (p.type === 'image' || p.type === 'live_photo') {
|
|
422
|
-
const
|
|
423
|
-
if (p.type === 'live_photo' && p.live_photo?.length) {
|
|
424
|
-
for (const lp of p.live_photo) {
|
|
425
|
-
if (lp.image)
|
|
426
|
-
mediaList.push({ type: 'image', url: lp.image });
|
|
427
|
-
if (lp.video && config.sendLivePhotoVideos)
|
|
428
|
-
mediaList.push({ type: 'video', url: lp.video });
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
else if (p.images?.length) {
|
|
432
|
-
p.images.forEach(url => mediaList.push({ type: 'image', url }));
|
|
433
|
-
}
|
|
441
|
+
const imageUrls = p.images?.length ? p.images : [];
|
|
434
442
|
if (enableForward) {
|
|
435
|
-
for (const
|
|
436
|
-
|
|
437
|
-
forwardMessages.push(buildForwardNode(session, msg, botName));
|
|
443
|
+
for (const url of imageUrls) {
|
|
444
|
+
forwardMessages.push(buildForwardNode(session, koishi_1.h.image(url), botName));
|
|
438
445
|
}
|
|
439
446
|
}
|
|
440
447
|
else {
|
|
441
|
-
for (const
|
|
448
|
+
for (const url of imageUrls) {
|
|
442
449
|
try {
|
|
443
|
-
await sendWithTimeout(session,
|
|
450
|
+
await sendWithTimeout(session, koishi_1.h.image(url));
|
|
444
451
|
await delay(200);
|
|
445
452
|
}
|
|
446
453
|
catch { }
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -3,24 +3,22 @@
|
|
|
3
3
|
## 项目介绍 (Project Introduction)
|
|
4
4
|
|
|
5
5
|
### 中文
|
|
6
|
-
这是一个为 Koishi 机器人框架开发的**全平台视频/图集解析插件**,使用统一API接口,支持自动识别并解析抖音、快手、B站、小红书、微博、YouTube、TikTok、剪映、AcFun、知乎、虎牙等20
|
|
6
|
+
这是一个为 Koishi 机器人框架开发的**全平台视频/图集解析插件**,使用统一API接口,支持自动识别并解析抖音、快手、B站、小红书、微博、YouTube、TikTok、剪映、AcFun、知乎、虎牙等20+主流平台的短视频/图集链接。核心特性:
|
|
7
7
|
- 🌐 统一API解析,覆盖20+热门平台,无需繁琐配置
|
|
8
8
|
- 🤖 自动识别链接来源,即丢即用
|
|
9
|
-
- 🎨
|
|
9
|
+
- 🎨 完全自定义的解析结果格式,支持多项变量替换,变量无值自动隐藏行
|
|
10
10
|
- 🐛 内置Debug调试模式,可详细记录所有操作与API交互日志
|
|
11
|
-
- ⚡ 防重复解析、API重试、本地视频下载、多线程加速等实用功能
|
|
12
11
|
- 📤 支持OneBot平台消息合并转发,优化多图文展示体验
|
|
13
|
-
-
|
|
12
|
+
- 💬 所有提示文案均可自定义,适配多语言场景
|
|
14
13
|
|
|
15
14
|
### English
|
|
16
|
-
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
|
|
15
|
+
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 links from 20+ mainstream platforms such as Douyin, Kuaishou, Bilibili, Xiaohongshu, Weibo, YouTube, TikTok, Jianying, AcFun, Zhihu, Huya and more. Core features:
|
|
17
16
|
- 🌐 Unified API parsing, covering 20+ popular platforms without complex configuration
|
|
18
17
|
- 🤖 Auto-detection of link sources, just drop & go
|
|
19
|
-
- 🎨 Fully customizable parsing result format with variable substitutions
|
|
18
|
+
- 🎨 Fully customizable parsing result format with variable substitutions, empty variables hide the line automatically
|
|
20
19
|
- 🐛 Built-in Debug mode, recording detailed operations and API interaction logs
|
|
21
|
-
- ⚡ Duplicate parsing prevention, API retry, local video download, multithread acceleration
|
|
22
20
|
- 📤 Support OneBot message forwarding for better image/video display
|
|
23
|
-
-
|
|
21
|
+
- 💬 All prompt texts are customizable for multilingual scenarios
|
|
24
22
|
|
|
25
23
|
## 项目仓库 (Repository)
|
|
26
24
|
- GitHub: `https://github.com/Minecraft-1314/koishi-plugin-video-parser-all`
|
|
@@ -31,7 +29,6 @@ This is a **multi-platform video/image parsing plugin** developed for the Koishi
|
|
|
31
29
|
| 指令 (Command) | 说明 (Description) | 示例 (Example) |
|
|
32
30
|
|----------------|--------------------|----------------|
|
|
33
31
|
| `parse <url>` | 手动解析指定的视频/图集链接 | `parse https://v.douyin.com/xxxx/` |
|
|
34
|
-
| `clear-cache` | 清理解析缓存和临时下载的视频文件 | `clear-cache` |
|
|
35
32
|
|
|
36
33
|
## 配置项说明 (Configuration)
|
|
37
34
|
|
|
@@ -40,89 +37,72 @@ This is a **multi-platform video/image parsing plugin** developed for the Koishi
|
|
|
40
37
|
|--------|------|--------|------|
|
|
41
38
|
| `enable` | boolean | true | 是否启用视频解析插件 |
|
|
42
39
|
| `botName` | string | 视频解析机器人 | 合并转发消息中显示的机器人名称 |
|
|
43
|
-
| `showWaitingTip` | boolean | true |
|
|
44
|
-
| `
|
|
45
|
-
| `sameLinkInterval` | number | 180 | 相同链接重复解析间隔(秒),防止频繁解析 |
|
|
46
|
-
| `debug` | boolean | false | 是否开启Debug调试模式,控制台输出详细日志 |
|
|
47
|
-
| `debugFile` | boolean | false | 开启Debug时将日志同时写入本地`debug.log`文件 |
|
|
40
|
+
| `showWaitingTip` | boolean | true | 解析时是否显示等待提示 |
|
|
41
|
+
| `debug` | boolean | false | 是否开启 Debug 模式,在控制台输出详细日志 |
|
|
48
42
|
|
|
49
43
|
### 统一消息格式
|
|
50
44
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
51
45
|
|--------|------|--------|------|
|
|
52
|
-
| `unifiedMessageFormat` | string |
|
|
46
|
+
| `unifiedMessageFormat` | string | `\${标题}\n\${作者}\n\${简介}\n点赞:\${点赞数}\n收藏:\${收藏数}\n转发:\${转发数}\n播放:\${播放数}\n评论:\${评论数}` | 自定义解析结果的输出格式,支持变量替换。某行所有变量为空时自动隐藏该行 |
|
|
53
47
|
|
|
54
48
|
### 内容显示设置
|
|
55
49
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
56
50
|
|--------|------|--------|------|
|
|
57
|
-
| `showImageText` | boolean | true |
|
|
51
|
+
| `showImageText` | boolean | true | 是否发送解析后的文字内容 |
|
|
58
52
|
| `showVideoFile` | boolean | true | 是否发送视频文件(关闭则只发送视频链接) |
|
|
59
|
-
| `
|
|
53
|
+
| `maxDescLength` | number | 200 | 简介内容最大长度(字符),超出自动截断 |
|
|
60
54
|
|
|
61
|
-
###
|
|
55
|
+
### 网络与 API 设置
|
|
62
56
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
63
57
|
|--------|------|--------|------|
|
|
64
|
-
| `
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
| 配置项 | 类型 | 默认值 | 说明 |
|
|
68
|
-
|--------|------|--------|------|
|
|
69
|
-
| `timeout` | number | 180000 | API请求超时时间(毫秒) |
|
|
70
|
-
| `videoSendTimeout` | number | 60000 | 视频消息发送超时时间(毫秒,0为不限制) |
|
|
71
|
-
| `userAgent` | string | Chrome 124 UA | API请求使用的User-Agent标识 |
|
|
58
|
+
| `timeout` | number | 180000 | API 请求超时时间(毫秒) |
|
|
59
|
+
| `videoSendTimeout` | number | 60000 | 视频消息发送超时时间(毫秒,0 为不限制) |
|
|
60
|
+
| `userAgent` | string | Chrome 124 UA | API 请求使用的 User-Agent |
|
|
72
61
|
|
|
73
62
|
### 错误与重试设置
|
|
74
63
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
75
64
|
|--------|------|--------|------|
|
|
76
|
-
| `ignoreSendError` | boolean | true |
|
|
77
|
-
| `retryTimes` | number | 3 | API请求失败时的重试次数 |
|
|
78
|
-
| `retryInterval` | number | 1000 |
|
|
65
|
+
| `ignoreSendError` | boolean | true | 是否忽略消息发送失败,避免插件崩溃 |
|
|
66
|
+
| `retryTimes` | number | 3 | API 请求失败时的重试次数 |
|
|
67
|
+
| `retryInterval` | number | 1000 | 重试间隔时间(毫秒) |
|
|
79
68
|
|
|
80
69
|
### 发送方式设置
|
|
81
70
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
82
71
|
|--------|------|--------|------|
|
|
83
|
-
| `enableForward` | boolean | false |
|
|
84
|
-
| `downloadVideoBeforeSend` | boolean | false | 发送前先下载视频到本地并发送文件 |
|
|
85
|
-
| `maxVideoSize` | number | 0 | 最大视频下载大小限制(MB,0为不限制) |
|
|
86
|
-
| `downloadThreads` | number | 0 | 多线程下载线程数(0为单线程,最大10) |
|
|
72
|
+
| `enableForward` | boolean | false | 是否启用合并转发(仅 OneBot 平台) |
|
|
87
73
|
|
|
88
|
-
###
|
|
74
|
+
### 界面文字设置
|
|
89
75
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
90
76
|
|--------|------|--------|------|
|
|
91
|
-
| `
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
|
95
|
-
|
|
96
|
-
| `autoClearCacheInterval` | number | 0 | 自动清理缓存间隔(分钟,0为关闭自动清理) |
|
|
97
|
-
|
|
98
|
-
## 缓存机制说明 (Cache Mechanism)
|
|
99
|
-
- 临时视频默认存放目录:项目根目录 `temp_videos`
|
|
100
|
-
- 支持定时自动清空缓存、手动执行 `clear-cache` 一键清理
|
|
101
|
-
- 自动清理过期解析记录、残留分段下载文件,避免磁盘占用
|
|
77
|
+
| `waitingTipText` | string | 正在解析视频,请稍候... | 解析等待提示文字 |
|
|
78
|
+
| `unsupportedPlatformText` | string | 不支持该平台链接 | 不支持的平台提示 |
|
|
79
|
+
| `invalidLinkText` | string | 无效的视频链接 | 无效链接提示(parse 指令) |
|
|
80
|
+
| `parseErrorPrefix` | string | ❌ 解析失败: | 解析失败消息前缀 |
|
|
81
|
+
| `parseErrorItemFormat` | string | 【${url}】: ${msg} | 每条解析失败格式,可用 `${url}` `${msg}` |
|
|
102
82
|
|
|
103
83
|
## 支持的变量 (Supported Variables)
|
|
104
|
-
在 `unifiedMessageFormat`
|
|
84
|
+
在 `unifiedMessageFormat` 中可使用以下变量进行自定义格式化,某行所有变量均为空时该行不显示:
|
|
105
85
|
|
|
106
86
|
| 变量名 | 说明 | 适用平台 |
|
|
107
87
|
|--------|------|----------|
|
|
108
88
|
| `${标题}` | 视频/图集标题 | 所有平台 |
|
|
109
89
|
| `${作者}` | 作者/发布者名称 | 所有平台 |
|
|
110
90
|
| `${简介}` | 内容简介/描述 | 所有平台 |
|
|
111
|
-
| `${视频时长}` | 视频时长(时:分:秒) |
|
|
91
|
+
| `${视频时长}` | 视频时长(时:分:秒) | 视频 |
|
|
112
92
|
| `${点赞数}` | 点赞数量 | 所有平台 |
|
|
113
93
|
| `${收藏数}` | 收藏数量 | 所有平台 |
|
|
114
94
|
| `${转发数}` | 转发/分享数量 | 所有平台 |
|
|
115
95
|
| `${播放数}` | 播放量 | 部分平台 |
|
|
116
96
|
| `${评论数}` | 评论数量 | 所有平台 |
|
|
117
97
|
| `${发布时间}` | 发布时间(格式化) | 所有平台 |
|
|
118
|
-
| `${图片数量}` |
|
|
98
|
+
| `${图片数量}` | 图集图片数量(live_photo 或 images 的数量) | 图集 |
|
|
119
99
|
| `${作者ID}` | 作者唯一标识ID | 部分平台 |
|
|
120
|
-
| `${视频链接}` | 视频直链地址 |
|
|
100
|
+
| `${视频链接}` | 视频直链地址 | 视频 |
|
|
121
101
|
| `${封面}` | 封面图片地址 | 所有平台 |
|
|
122
102
|
| `${音乐作者}` | 背景音乐作者 | 部分平台 |
|
|
123
103
|
| `${音乐标题}` | 背景音乐标题 | 部分平台 |
|
|
124
104
|
|
|
125
|
-
> 注:部分变量可能因平台API
|
|
105
|
+
> 注:部分变量可能因平台API返回数据不同而显示为空,空值行会自动隐藏。
|
|
126
106
|
|
|
127
107
|
## 支持的平台 (Supported Platforms)
|
|
128
108
|
| 平台名称 | 关键词识别 | 解析能力 |
|