koishi-plugin-video-parser-all 1.0.4 → 1.0.5
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 +47 -46
- package/package.json +1 -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
|
}
|
|
@@ -744,9 +738,11 @@ function apply(ctx, config) {
|
|
|
744
738
|
forwardMessages.push(buildForwardNode(session, koishi_1.h.image(imgUrl), botName));
|
|
745
739
|
}
|
|
746
740
|
}
|
|
747
|
-
if (p.video
|
|
741
|
+
if (p.video) {
|
|
748
742
|
forwardMessages.push(buildForwardNode(session, `视频链接:${p.video}`, botName));
|
|
749
|
-
|
|
743
|
+
if (config.showVideoFile && (p.type === 'video' || (p.type === 'live' && !p.live_photo?.length && !p.images?.length))) {
|
|
744
|
+
videoItems.push(p);
|
|
745
|
+
}
|
|
750
746
|
}
|
|
751
747
|
}
|
|
752
748
|
if (forwardMessages.length) {
|
|
@@ -786,11 +782,16 @@ function apply(ctx, config) {
|
|
|
786
782
|
await delay(300);
|
|
787
783
|
}
|
|
788
784
|
if (p.video && (p.type === 'video' || (p.type === 'live' && !p.live_photo?.length && !p.images?.length))) {
|
|
789
|
-
|
|
790
|
-
|
|
785
|
+
if (config.showVideoFile) {
|
|
786
|
+
try {
|
|
787
|
+
await sendVideoFile(session, p.video);
|
|
788
|
+
}
|
|
789
|
+
catch (err) {
|
|
790
|
+
debugLog('ERROR', `视频发送失败: ${getErrorMessage(err)}`);
|
|
791
|
+
}
|
|
791
792
|
}
|
|
792
|
-
|
|
793
|
-
|
|
793
|
+
else {
|
|
794
|
+
await sendWithTimeout(session, `视频链接:${p.video}`);
|
|
794
795
|
}
|
|
795
796
|
await delay(500);
|
|
796
797
|
}
|
package/package.json
CHANGED