koishi-plugin-video-parser-all 0.4.8 → 0.4.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 +6 -2
- package/lib/index.js +49 -16
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from 'koishi';
|
|
1
|
+
import { Schema, Context } from 'koishi';
|
|
2
2
|
export declare const name = "video-parser-all";
|
|
3
3
|
export declare const Config: Schema<{
|
|
4
4
|
enable?: boolean | null | undefined;
|
|
@@ -11,6 +11,8 @@ export declare const Config: Schema<{
|
|
|
11
11
|
maxVideoSize?: number | null | undefined;
|
|
12
12
|
downloadThreads?: number | null | undefined;
|
|
13
13
|
enableApiSelection?: boolean | null | undefined;
|
|
14
|
+
debugMode?: boolean | null | undefined;
|
|
15
|
+
logLevel?: "info" | "warn" | "error" | "debug" | null | undefined;
|
|
14
16
|
} & import("cosmokit").Dict & {
|
|
15
17
|
platformEnable?: ({
|
|
16
18
|
bilibili?: boolean | null | undefined;
|
|
@@ -72,6 +74,8 @@ export declare const Config: Schema<{
|
|
|
72
74
|
maxVideoSize: number;
|
|
73
75
|
downloadThreads: number;
|
|
74
76
|
enableApiSelection: boolean;
|
|
77
|
+
debugMode: boolean;
|
|
78
|
+
logLevel: "info" | "warn" | "error" | "debug";
|
|
75
79
|
} & import("cosmokit").Dict & {
|
|
76
80
|
platformEnable: Schemastery.ObjectT<{
|
|
77
81
|
bilibili: Schema<boolean, boolean>;
|
|
@@ -133,4 +137,4 @@ export declare const Config: Schema<{
|
|
|
133
137
|
zuiyou: Schema<"https://api.bugpk.com/api/short_videos" | "https://api.bugpk.com/api/zuiyou" | "https://api.suyanw.cn/api/zuiyou.php", "https://api.bugpk.com/api/short_videos" | "https://api.bugpk.com/api/zuiyou" | "https://api.suyanw.cn/api/zuiyou.php">;
|
|
134
138
|
}>>;
|
|
135
139
|
}>))))>;
|
|
136
|
-
export declare function apply(ctx:
|
|
140
|
+
export declare function apply(ctx: Context, config: any): void;
|
package/lib/index.js
CHANGED
|
@@ -44,6 +44,8 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
44
44
|
maxVideoSize: koishi_1.Schema.number().min(0).default(50).description('允许发送的最大视频大小(MB)'),
|
|
45
45
|
downloadThreads: koishi_1.Schema.number().min(0).default(4).description('视频下载线程数'),
|
|
46
46
|
enableApiSelection: koishi_1.Schema.boolean().default(false).description('是否启用API选择设置(开启后可选择首选解析源)'),
|
|
47
|
+
debugMode: koishi_1.Schema.boolean().default(false).description('调试模式(输出详细日志)'),
|
|
48
|
+
logLevel: koishi_1.Schema.union(['info', 'warn', 'error', 'debug']).default('info').description('日志级别'),
|
|
47
49
|
}).description('基础设置'),
|
|
48
50
|
koishi_1.Schema.object({
|
|
49
51
|
platformEnable: koishi_1.Schema.object({
|
|
@@ -592,6 +594,18 @@ function apply(ctx, config) {
|
|
|
592
594
|
if (!worker_threads_1.isMainThread)
|
|
593
595
|
return;
|
|
594
596
|
clearAllCache();
|
|
597
|
+
const logLevelMap = {
|
|
598
|
+
'debug': 0,
|
|
599
|
+
'info': 1,
|
|
600
|
+
'warn': 2,
|
|
601
|
+
'error': 3
|
|
602
|
+
};
|
|
603
|
+
if (config.debugMode) {
|
|
604
|
+
logger.level = logLevelMap['debug'];
|
|
605
|
+
}
|
|
606
|
+
else if (config.logLevel && logLevelMap[config.logLevel]) {
|
|
607
|
+
logger.level = logLevelMap[config.logLevel];
|
|
608
|
+
}
|
|
595
609
|
logger.info('视频解析插件已加载');
|
|
596
610
|
const http = axios_1.default.create({
|
|
597
611
|
timeout: config.timeout,
|
|
@@ -605,11 +619,17 @@ function apply(ctx, config) {
|
|
|
605
619
|
return result;
|
|
606
620
|
}
|
|
607
621
|
catch (error) {
|
|
622
|
+
if (config.debugMode) {
|
|
623
|
+
logger.debug(`API调用失败 ${apiName}: ${getErrorMessage(error)}`);
|
|
624
|
+
}
|
|
608
625
|
return null;
|
|
609
626
|
}
|
|
610
627
|
}
|
|
611
628
|
async function requestAPI(apiUrl, params, method = 'GET') {
|
|
612
629
|
try {
|
|
630
|
+
if (config.debugMode) {
|
|
631
|
+
logger.debug(`请求API: ${apiUrl}, 参数: ${JSON.stringify(params)}, 方法: ${method}`);
|
|
632
|
+
}
|
|
613
633
|
let response;
|
|
614
634
|
if (method.toUpperCase() === 'GET') {
|
|
615
635
|
response = await http.get(apiUrl, { params });
|
|
@@ -617,9 +637,15 @@ function apply(ctx, config) {
|
|
|
617
637
|
else {
|
|
618
638
|
response = await http.post(apiUrl, params);
|
|
619
639
|
}
|
|
640
|
+
if (config.debugMode) {
|
|
641
|
+
logger.debug(`API响应: ${apiUrl}, 状态码: ${response.status}, 数据: ${JSON.stringify(response.data).substring(0, 500)}`);
|
|
642
|
+
}
|
|
620
643
|
return response.data;
|
|
621
644
|
}
|
|
622
645
|
catch (error) {
|
|
646
|
+
if (config.debugMode) {
|
|
647
|
+
logger.debug(`API请求失败: ${apiUrl}, 错误: ${getErrorMessage(error)}`);
|
|
648
|
+
}
|
|
623
649
|
throw error;
|
|
624
650
|
}
|
|
625
651
|
}
|
|
@@ -1037,25 +1063,28 @@ function apply(ctx, config) {
|
|
|
1037
1063
|
}
|
|
1038
1064
|
}
|
|
1039
1065
|
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1066
|
+
// 修复 middleware 的 next 参数类型
|
|
1067
|
+
ctx.middleware(async (session, next) => {
|
|
1068
|
+
if (!config.enable || !config.autoParse) {
|
|
1069
|
+
return next();
|
|
1070
|
+
}
|
|
1071
|
+
let textContent = session.content || '';
|
|
1044
1072
|
if (Array.isArray(session.elements)) {
|
|
1045
|
-
session.elements
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
});
|
|
1073
|
+
textContent = session.elements
|
|
1074
|
+
.filter((element) => element.type === 'text')
|
|
1075
|
+
.map((element) => element.content)
|
|
1076
|
+
.join('');
|
|
1050
1077
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1078
|
+
if (!textContent.trim()) {
|
|
1079
|
+
return next();
|
|
1053
1080
|
}
|
|
1054
|
-
if (!textContent.trim())
|
|
1055
|
-
return;
|
|
1056
1081
|
const urls = extractUrl(textContent.trim(), config.enableBvAvParse);
|
|
1057
|
-
if (!urls.length)
|
|
1058
|
-
return;
|
|
1082
|
+
if (!urls.length) {
|
|
1083
|
+
return next();
|
|
1084
|
+
}
|
|
1085
|
+
if (config.debugMode) {
|
|
1086
|
+
logger.debug(`检测到链接: ${JSON.stringify(urls)}`);
|
|
1087
|
+
}
|
|
1059
1088
|
const key = `${session.platform}:${session.userId}:${session.channelId}`;
|
|
1060
1089
|
const uniqueUrls = [...new Set(urls)];
|
|
1061
1090
|
if (linkBuffer.has(key)) {
|
|
@@ -1078,9 +1107,13 @@ function apply(ctx, config) {
|
|
|
1078
1107
|
timer: setTimeout(() => flush(session), config.messageBufferDelay * 1000),
|
|
1079
1108
|
tipMsgId
|
|
1080
1109
|
});
|
|
1110
|
+
return next();
|
|
1081
1111
|
});
|
|
1082
1112
|
ctx.command('parse <url>', '手动解析视频链接')
|
|
1083
|
-
.action(async (
|
|
1113
|
+
.action(async (argv, url) => {
|
|
1114
|
+
const session = argv.session;
|
|
1115
|
+
if (!session)
|
|
1116
|
+
return '解析失败:未找到会话 (错误码: 5000)';
|
|
1084
1117
|
if (!url)
|
|
1085
1118
|
return '请输入视频链接 (错误码: 5001)';
|
|
1086
1119
|
const urls = extractUrl(url, config.enableBvAvParse);
|