koishi-plugin-video-parser-all 0.0.8 → 0.0.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.js +11 -6
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -36,7 +36,7 @@ function apply(ctx, config) {
|
|
|
36
36
|
const request = axios_1.default.create({
|
|
37
37
|
timeout: config.timeout,
|
|
38
38
|
headers: {
|
|
39
|
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
|
39
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
// 抖音解析
|
|
@@ -74,7 +74,7 @@ function apply(ctx, config) {
|
|
|
74
74
|
video: videoUrl
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
//
|
|
77
|
+
// 核心:只走专属接口,无通用API
|
|
78
78
|
async function parseVideo(url) {
|
|
79
79
|
// 抖音
|
|
80
80
|
if (url.includes('douyin.com') || url.includes('v.douyin.com')) {
|
|
@@ -150,9 +150,13 @@ function apply(ctx, config) {
|
|
|
150
150
|
ctx.on('message', async (session) => {
|
|
151
151
|
if (!config.enable)
|
|
152
152
|
return;
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
const content = session.content.trim();
|
|
154
|
+
// 关键修改:仅提取 http/https 开头的链接,过滤所有前后多余字符
|
|
155
|
+
const urlMatch = content.match(/https?:\/\/[^\s]+/);
|
|
156
|
+
if (!urlMatch)
|
|
157
|
+
return; // 无有效链接则直接返回
|
|
158
|
+
const url = urlMatch[0]; // 只取匹配到的纯链接
|
|
159
|
+
// 去重逻辑
|
|
156
160
|
const hash = crypto_1.default.createHash('md5').update(url).digest('hex');
|
|
157
161
|
const now = Date.now();
|
|
158
162
|
if (processed.get(hash) && now - processed.get(hash) < config.sameLinkInterval * 1000)
|
|
@@ -163,9 +167,10 @@ function apply(ctx, config) {
|
|
|
163
167
|
const data = await parseVideo(url);
|
|
164
168
|
await sendResult(session, data);
|
|
165
169
|
});
|
|
170
|
+
// 定时清理缓存
|
|
166
171
|
setInterval(() => {
|
|
167
172
|
const now = Date.now();
|
|
168
173
|
processed.forEach((t, k) => now - t > 86400000 && processed.delete(k));
|
|
169
174
|
}, 3600000);
|
|
170
|
-
ctx.logger.info('✅
|
|
175
|
+
ctx.logger.info('✅ 纯专属接口解析(仅提取HTTP/HTTPS链接)加载完成');
|
|
171
176
|
}
|