koishi-plugin-video-parser-all 0.7.0 → 0.7.2
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 -19
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -284,9 +284,8 @@ function cleanUrl(url) {
|
|
|
284
284
|
try {
|
|
285
285
|
url = url.replace(/&/g, '&');
|
|
286
286
|
const urlObj = new URL(url);
|
|
287
|
-
if (urlObj.hostname.includes('xiaohongshu.com')) {
|
|
288
|
-
|
|
289
|
-
return urlObj.origin + urlObj.pathname;
|
|
287
|
+
if (urlObj.hostname.includes('xiaohongshu.com') || urlObj.hostname.includes('xhslink.com')) {
|
|
288
|
+
return urlObj.href;
|
|
290
289
|
}
|
|
291
290
|
if (urlObj.hostname.includes('douyin.com') || urlObj.hostname.includes('v.douyin.com')) {
|
|
292
291
|
urlObj.searchParams.delete('source');
|
|
@@ -301,15 +300,17 @@ function cleanUrl(url) {
|
|
|
301
300
|
}
|
|
302
301
|
async function resolveShortUrl(url) {
|
|
303
302
|
try {
|
|
304
|
-
const res = await axios_1.default.
|
|
303
|
+
const res = await axios_1.default.get(url, {
|
|
305
304
|
timeout: 10000,
|
|
306
305
|
maxRedirects: 10,
|
|
307
306
|
headers: {
|
|
308
307
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
309
308
|
'Referer': 'https://www.baidu.com/',
|
|
310
|
-
}
|
|
309
|
+
},
|
|
310
|
+
validateStatus: status => true
|
|
311
311
|
});
|
|
312
|
-
|
|
312
|
+
const finalUrl = res.request.res?.responseUrl || url;
|
|
313
|
+
return cleanUrl(finalUrl);
|
|
313
314
|
}
|
|
314
315
|
catch (e) {
|
|
315
316
|
return cleanUrl(url);
|
|
@@ -634,26 +635,17 @@ function apply(ctx, config) {
|
|
|
634
635
|
let lastError = null;
|
|
635
636
|
for (let i = 0; i <= retryTimes; i++) {
|
|
636
637
|
try {
|
|
637
|
-
const params = { url
|
|
638
|
+
const params = { url };
|
|
638
639
|
let res;
|
|
639
640
|
if (platform === 'xiaohongshu') {
|
|
640
641
|
res = await http.post(API_CONFIG[platform], new URLSearchParams(params), {
|
|
641
|
-
timeout: config.timeout
|
|
642
|
-
headers: {
|
|
643
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
644
|
-
'Origin': 'https://api.bugpk.com',
|
|
645
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
646
|
-
}
|
|
642
|
+
timeout: config.timeout
|
|
647
643
|
});
|
|
648
644
|
}
|
|
649
645
|
else {
|
|
650
646
|
res = await http.get(API_CONFIG[platform], {
|
|
651
647
|
params,
|
|
652
|
-
timeout: config.timeout
|
|
653
|
-
headers: {
|
|
654
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
655
|
-
'Origin': 'https://www.baidu.com'
|
|
656
|
-
}
|
|
648
|
+
timeout: config.timeout
|
|
657
649
|
});
|
|
658
650
|
}
|
|
659
651
|
return res.data;
|
|
@@ -723,7 +715,7 @@ function apply(ctx, config) {
|
|
|
723
715
|
}
|
|
724
716
|
}
|
|
725
717
|
async function processSingleUrl(session, url) {
|
|
726
|
-
const hash = crypto_1.default.createHash('md5').update(url).digest('hex');
|
|
718
|
+
const hash = crypto_1.default.createHash('md5').update(url + Date.now().toString()).digest('hex');
|
|
727
719
|
const now = Date.now();
|
|
728
720
|
if (processed.get(hash) && now - processed.get(hash) < config.sameLinkInterval * 1000) {
|
|
729
721
|
logger.warn(`相同链接重复解析: ${url}`);
|
package/package.json
CHANGED