koishi-plugin-video-parser-all 1.0.4 → 1.0.6
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 +54 -63
- package/package.json +1 -1
- package/readme.md +0 -1
package/lib/index.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export declare const Config: Schema<{
|
|
|
15
15
|
tempDir?: string | null | undefined;
|
|
16
16
|
maxVideoSize?: number | null | undefined;
|
|
17
17
|
forceDownloadVideo?: boolean | null | undefined;
|
|
18
|
-
videoLoadWaitTime?: number | null | undefined;
|
|
19
18
|
} & {
|
|
20
19
|
timeout?: number | null | undefined;
|
|
21
20
|
videoSendTimeout?: number | null | undefined;
|
|
@@ -47,7 +46,6 @@ export declare const Config: Schema<{
|
|
|
47
46
|
tempDir: string;
|
|
48
47
|
maxVideoSize: number;
|
|
49
48
|
forceDownloadVideo: boolean;
|
|
50
|
-
videoLoadWaitTime: number;
|
|
51
49
|
} & {
|
|
52
50
|
timeout: number;
|
|
53
51
|
videoSendTimeout: number;
|
package/lib/index.js
CHANGED
|
@@ -31,7 +31,6 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
31
31
|
tempDir: koishi_1.Schema.string().default('./temp_videos').description('临时视频存储目录'),
|
|
32
32
|
maxVideoSize: koishi_1.Schema.number().min(0).step(1).default(0).description('最大下载视频大小(MB),0 为不限制大小'),
|
|
33
33
|
forceDownloadVideo: koishi_1.Schema.boolean().default(false).description('强制下载视频后发送'),
|
|
34
|
-
videoLoadWaitTime: koishi_1.Schema.number().min(0).step(1).default(180000).description('视频链接加载等待时间(毫秒),获取到视频链接后等待指定时间再发送,0为不等待'),
|
|
35
34
|
}).description('内容显示设置'),
|
|
36
35
|
koishi_1.Schema.object({
|
|
37
36
|
timeout: koishi_1.Schema.number().min(0).step(1).default(180000).description('API 请求超时(毫秒)'),
|
|
@@ -517,21 +516,6 @@ function getErrorMessage(error) {
|
|
|
517
516
|
return error.message;
|
|
518
517
|
return String(error);
|
|
519
518
|
}
|
|
520
|
-
function isSpecialPlatformVideo(url) {
|
|
521
|
-
const specialHosts = [
|
|
522
|
-
'bilibili.com',
|
|
523
|
-
'akamaized.net',
|
|
524
|
-
'hdslb.com',
|
|
525
|
-
'xiaohongshu.com',
|
|
526
|
-
'xhslink.com',
|
|
527
|
-
'zhihu.com',
|
|
528
|
-
'weibo.com',
|
|
529
|
-
'sinaimg.cn',
|
|
530
|
-
'ixigua.com',
|
|
531
|
-
'toutiao.com',
|
|
532
|
-
];
|
|
533
|
-
return specialHosts.some(host => url.includes(host));
|
|
534
|
-
}
|
|
535
519
|
function apply(ctx, config) {
|
|
536
520
|
debugEnabled = config.debug || false;
|
|
537
521
|
debugLog('INFO', '插件初始化开始');
|
|
@@ -658,39 +642,49 @@ function apply(ctx, config) {
|
|
|
658
642
|
async function sendVideoFile(session, videoUrl) {
|
|
659
643
|
if (!videoUrl)
|
|
660
644
|
throw new Error('视频链接为空');
|
|
661
|
-
if (config.videoLoadWaitTime > 0) {
|
|
662
|
-
await delay(config.videoLoadWaitTime);
|
|
663
|
-
}
|
|
664
|
-
await sendWithTimeout(session, `视频链接:${videoUrl}`).catch(() => { });
|
|
665
645
|
if (!config.showVideoFile) {
|
|
666
|
-
return
|
|
646
|
+
return await sendWithTimeout(session, `视频链接:${videoUrl}`);
|
|
667
647
|
}
|
|
668
|
-
|
|
648
|
+
const sendLinkAsFallback = async () => {
|
|
649
|
+
await sendWithTimeout(session, `视频链接:${videoUrl}`).catch(() => { });
|
|
650
|
+
};
|
|
651
|
+
const tryDownloadAndSend = async () => {
|
|
652
|
+
let tempFilePath = null;
|
|
669
653
|
try {
|
|
670
|
-
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
654
|
+
tempFilePath = await downloadVideoFile(videoUrl, config.tempDir || './temp_videos', config.videoDownloadTimeout || 120000, config.maxVideoSize || 0);
|
|
655
|
+
const localFile = `file://${tempFilePath}`;
|
|
656
|
+
debugLog('INFO', `发送本地视频文件: ${localFile}`);
|
|
657
|
+
return await sendWithTimeout(session, koishi_1.h.video(localFile));
|
|
658
|
+
}
|
|
659
|
+
finally {
|
|
660
|
+
if (tempFilePath) {
|
|
661
|
+
promises_1.default.unlink(tempFilePath).catch(e => debugLog('WARN', `删除临时文件失败: ${e}`));
|
|
675
662
|
}
|
|
676
663
|
}
|
|
664
|
+
};
|
|
665
|
+
if (config.forceDownloadVideo) {
|
|
666
|
+
try {
|
|
667
|
+
return await tryDownloadAndSend();
|
|
668
|
+
}
|
|
677
669
|
catch (err) {
|
|
678
|
-
debugLog('ERROR',
|
|
670
|
+
debugLog('ERROR', `下载并发送视频失败: ${getErrorMessage(err)}`);
|
|
671
|
+
await sendLinkAsFallback();
|
|
679
672
|
}
|
|
680
673
|
}
|
|
681
674
|
else {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
675
|
+
try {
|
|
676
|
+
debugLog('INFO', `尝试直接发送视频URL: ${videoUrl.substring(0, 100)}...`);
|
|
677
|
+
return await sendWithTimeout(session, koishi_1.h.video(videoUrl));
|
|
678
|
+
}
|
|
679
|
+
catch (err) {
|
|
680
|
+
debugLog('ERROR', `直接发送URL失败,尝试下载: ${getErrorMessage(err)}`);
|
|
681
|
+
try {
|
|
682
|
+
return await tryDownloadAndSend();
|
|
683
|
+
}
|
|
684
|
+
catch (downloadErr) {
|
|
685
|
+
debugLog('ERROR', `下载并发送视频也失败: ${getErrorMessage(downloadErr)}`);
|
|
686
|
+
await sendLinkAsFallback();
|
|
687
|
+
}
|
|
694
688
|
}
|
|
695
689
|
}
|
|
696
690
|
}
|
|
@@ -724,11 +718,28 @@ function apply(ctx, config) {
|
|
|
724
718
|
debugLog('INFO', '没有成功解析的内容');
|
|
725
719
|
return;
|
|
726
720
|
}
|
|
721
|
+
// 先发送所有视频(单独发送,在合并转发之前)
|
|
722
|
+
for (const item of items) {
|
|
723
|
+
const p = item.parsed;
|
|
724
|
+
if (p.video && (p.type === 'video' || (p.type === 'live' && !p.live_photo?.length && !p.images?.length))) {
|
|
725
|
+
if (config.showVideoFile) {
|
|
726
|
+
try {
|
|
727
|
+
await sendVideoFile(session, p.video);
|
|
728
|
+
}
|
|
729
|
+
catch (e) {
|
|
730
|
+
debugLog('ERROR', `视频发送失败: ${getErrorMessage(e)}`);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
await sendWithTimeout(session, `视频链接:${p.video}`);
|
|
735
|
+
}
|
|
736
|
+
await delay(500);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
727
739
|
const enableForward = config.enableForward && session.platform === 'onebot';
|
|
728
740
|
const botName = config.botName || '视频解析机器人';
|
|
729
741
|
if (enableForward) {
|
|
730
742
|
const forwardMessages = [];
|
|
731
|
-
const videoItems = [];
|
|
732
743
|
for (const item of items) {
|
|
733
744
|
const p = item.parsed;
|
|
734
745
|
const text = item.text;
|
|
@@ -744,10 +755,7 @@ function apply(ctx, config) {
|
|
|
744
755
|
forwardMessages.push(buildForwardNode(session, koishi_1.h.image(imgUrl), botName));
|
|
745
756
|
}
|
|
746
757
|
}
|
|
747
|
-
|
|
748
|
-
forwardMessages.push(buildForwardNode(session, `视频链接:${p.video}`, botName));
|
|
749
|
-
videoItems.push(p);
|
|
750
|
-
}
|
|
758
|
+
// 视频已单独发送,合并转发中不再添加
|
|
751
759
|
}
|
|
752
760
|
if (forwardMessages.length) {
|
|
753
761
|
const forwardMsg = (0, koishi_1.h)('message', { forward: true }, forwardMessages.slice(0, 100));
|
|
@@ -763,17 +771,9 @@ function apply(ctx, config) {
|
|
|
763
771
|
}
|
|
764
772
|
}
|
|
765
773
|
}
|
|
766
|
-
for (const p of videoItems) {
|
|
767
|
-
try {
|
|
768
|
-
await sendVideoFile(session, p.video);
|
|
769
|
-
}
|
|
770
|
-
catch (err) {
|
|
771
|
-
debugLog('ERROR', `视频发送失败: ${getErrorMessage(err)}`);
|
|
772
|
-
}
|
|
773
|
-
await delay(500);
|
|
774
|
-
}
|
|
775
774
|
}
|
|
776
775
|
else {
|
|
776
|
+
// 非合并转发,只发送文字、封面、图片(视频已在之前发过)
|
|
777
777
|
for (const item of items) {
|
|
778
778
|
const p = item.parsed;
|
|
779
779
|
const text = item.text;
|
|
@@ -785,15 +785,6 @@ function apply(ctx, config) {
|
|
|
785
785
|
await sendWithTimeout(session, koishi_1.h.image(p.cover)).catch(() => { });
|
|
786
786
|
await delay(300);
|
|
787
787
|
}
|
|
788
|
-
if (p.video && (p.type === 'video' || (p.type === 'live' && !p.live_photo?.length && !p.images?.length))) {
|
|
789
|
-
try {
|
|
790
|
-
await sendVideoFile(session, p.video);
|
|
791
|
-
}
|
|
792
|
-
catch (err) {
|
|
793
|
-
debugLog('ERROR', `视频发送失败: ${getErrorMessage(err)}`);
|
|
794
|
-
}
|
|
795
|
-
await delay(500);
|
|
796
|
-
}
|
|
797
788
|
if (p.type === 'image' || p.type === 'live_photo' || (p.type === 'live' && (p.live_photo?.length || p.images?.length))) {
|
|
798
789
|
const imageUrls = p.images?.length ? p.images : (p.live_photo?.map(lp => lp.image) ?? []);
|
|
799
790
|
for (const imgUrl of imageUrls) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -63,7 +63,6 @@ This is a **multi-platform video/image parsing plugin** developed for the Koishi
|
|
|
63
63
|
| `tempDir` | string | `./temp_videos` | 临时视频存储目录 |
|
|
64
64
|
| `maxVideoSize` | number | 0 | 最大下载视频大小(MB),0 为不限制大小 |
|
|
65
65
|
| `forceDownloadVideo` | boolean | false | 强制下载视频后发送 |
|
|
66
|
-
| `videoLoadWaitTime` | number | 180000 | 视频链接加载等待时间(毫秒),获取到视频链接后等待指定时间再发送,0为不等待 |
|
|
67
66
|
|
|
68
67
|
### 网络与 API 设置
|
|
69
68
|
| 配置项 | 类型 | 默认值 | 说明 |
|