koishi-plugin-video-parser-all 0.8.8 → 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 +11 -12
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,19 +3,19 @@
|
|
|
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
11
|
- 📤 支持OneBot平台消息合并转发,优化多图文展示体验
|
|
12
12
|
- 💬 所有提示文案均可自定义,适配多语言场景
|
|
13
13
|
|
|
14
14
|
### English
|
|
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
|
|
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:
|
|
16
16
|
- 🌐 Unified API parsing, covering 20+ popular platforms without complex configuration
|
|
17
17
|
- 🤖 Auto-detection of link sources, just drop & go
|
|
18
|
-
- 🎨 Fully customizable parsing result format with variable substitutions
|
|
18
|
+
- 🎨 Fully customizable parsing result format with variable substitutions, empty variables hide the line automatically
|
|
19
19
|
- 🐛 Built-in Debug mode, recording detailed operations and API interaction logs
|
|
20
20
|
- 📤 Support OneBot message forwarding for better image/video display
|
|
21
21
|
- 💬 All prompt texts are customizable for multilingual scenarios
|
|
@@ -43,14 +43,13 @@ This is a **multi-platform video/image parsing plugin** developed for the Koishi
|
|
|
43
43
|
### 统一消息格式
|
|
44
44
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
45
45
|
|--------|------|--------|------|
|
|
46
|
-
| `unifiedMessageFormat` | string | `\${标题}\n\${作者}\n\${简介}\n点赞:\${点赞数}\n收藏:\${收藏数}\n转发:\${转发数}\n播放:\${播放数}\n评论:\${评论数}` |
|
|
46
|
+
| `unifiedMessageFormat` | string | `\${标题}\n\${作者}\n\${简介}\n点赞:\${点赞数}\n收藏:\${收藏数}\n转发:\${转发数}\n播放:\${播放数}\n评论:\${评论数}` | 自定义解析结果的输出格式,支持变量替换。某行所有变量为空时自动隐藏该行 |
|
|
47
47
|
|
|
48
48
|
### 内容显示设置
|
|
49
49
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
50
50
|
|--------|------|--------|------|
|
|
51
51
|
| `showImageText` | boolean | true | 是否发送解析后的文字内容 |
|
|
52
52
|
| `showVideoFile` | boolean | true | 是否发送视频文件(关闭则只发送视频链接) |
|
|
53
|
-
| `sendLivePhotoVideos` | boolean | true | 是否发送实况图片附带的短视频(仅 live_photo 类型) |
|
|
54
53
|
| `maxDescLength` | number | 200 | 简介内容最大长度(字符),超出自动截断 |
|
|
55
54
|
|
|
56
55
|
### 网络与 API 设置
|
|
@@ -77,33 +76,33 @@ This is a **multi-platform video/image parsing plugin** developed for the Koishi
|
|
|
77
76
|
|--------|------|--------|------|
|
|
78
77
|
| `waitingTipText` | string | 正在解析视频,请稍候... | 解析等待提示文字 |
|
|
79
78
|
| `unsupportedPlatformText` | string | 不支持该平台链接 | 不支持的平台提示 |
|
|
80
|
-
| `invalidLinkText` | string | 无效的视频链接 |
|
|
79
|
+
| `invalidLinkText` | string | 无效的视频链接 | 无效链接提示(parse 指令) |
|
|
81
80
|
| `parseErrorPrefix` | string | ❌ 解析失败: | 解析失败消息前缀 |
|
|
82
81
|
| `parseErrorItemFormat` | string | 【${url}】: ${msg} | 每条解析失败格式,可用 `${url}` `${msg}` |
|
|
83
82
|
|
|
84
83
|
## 支持的变量 (Supported Variables)
|
|
85
|
-
在 `unifiedMessageFormat`
|
|
84
|
+
在 `unifiedMessageFormat` 中可使用以下变量进行自定义格式化,某行所有变量均为空时该行不显示:
|
|
86
85
|
|
|
87
86
|
| 变量名 | 说明 | 适用平台 |
|
|
88
87
|
|--------|------|----------|
|
|
89
88
|
| `${标题}` | 视频/图集标题 | 所有平台 |
|
|
90
89
|
| `${作者}` | 作者/发布者名称 | 所有平台 |
|
|
91
90
|
| `${简介}` | 内容简介/描述 | 所有平台 |
|
|
92
|
-
| `${视频时长}` | 视频时长(时:分:秒) |
|
|
91
|
+
| `${视频时长}` | 视频时长(时:分:秒) | 视频 |
|
|
93
92
|
| `${点赞数}` | 点赞数量 | 所有平台 |
|
|
94
93
|
| `${收藏数}` | 收藏数量 | 所有平台 |
|
|
95
94
|
| `${转发数}` | 转发/分享数量 | 所有平台 |
|
|
96
95
|
| `${播放数}` | 播放量 | 部分平台 |
|
|
97
96
|
| `${评论数}` | 评论数量 | 所有平台 |
|
|
98
97
|
| `${发布时间}` | 发布时间(格式化) | 所有平台 |
|
|
99
|
-
| `${图片数量}` |
|
|
98
|
+
| `${图片数量}` | 图集图片数量(live_photo 或 images 的数量) | 图集 |
|
|
100
99
|
| `${作者ID}` | 作者唯一标识ID | 部分平台 |
|
|
101
|
-
| `${视频链接}` | 视频直链地址 |
|
|
100
|
+
| `${视频链接}` | 视频直链地址 | 视频 |
|
|
102
101
|
| `${封面}` | 封面图片地址 | 所有平台 |
|
|
103
102
|
| `${音乐作者}` | 背景音乐作者 | 部分平台 |
|
|
104
103
|
| `${音乐标题}` | 背景音乐标题 | 部分平台 |
|
|
105
104
|
|
|
106
|
-
> 注:部分变量可能因平台API
|
|
105
|
+
> 注:部分变量可能因平台API返回数据不同而显示为空,空值行会自动隐藏。
|
|
107
106
|
|
|
108
107
|
## 支持的平台 (Supported Platforms)
|
|
109
108
|
| 平台名称 | 关键词识别 | 解析能力 |
|