koishi-plugin-video-parser-all 0.7.1 → 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 -24
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -284,10 +284,7 @@ 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
|
-
const pathname = urlObj.pathname;
|
|
289
|
-
urlObj.searchParams.forEach((_, key) => urlObj.searchParams.delete(key));
|
|
290
|
-
urlObj.pathname = pathname;
|
|
287
|
+
if (urlObj.hostname.includes('xiaohongshu.com') || urlObj.hostname.includes('xhslink.com')) {
|
|
291
288
|
return urlObj.href;
|
|
292
289
|
}
|
|
293
290
|
if (urlObj.hostname.includes('douyin.com') || urlObj.hostname.includes('v.douyin.com')) {
|
|
@@ -303,16 +300,17 @@ function cleanUrl(url) {
|
|
|
303
300
|
}
|
|
304
301
|
async function resolveShortUrl(url) {
|
|
305
302
|
try {
|
|
306
|
-
const res = await axios_1.default.
|
|
307
|
-
timeout:
|
|
308
|
-
maxRedirects:
|
|
303
|
+
const res = await axios_1.default.get(url, {
|
|
304
|
+
timeout: 10000,
|
|
305
|
+
maxRedirects: 10,
|
|
309
306
|
headers: {
|
|
310
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',
|
|
311
308
|
'Referer': 'https://www.baidu.com/',
|
|
312
309
|
},
|
|
313
|
-
validateStatus:
|
|
310
|
+
validateStatus: status => true
|
|
314
311
|
});
|
|
315
|
-
|
|
312
|
+
const finalUrl = res.request.res?.responseUrl || url;
|
|
313
|
+
return cleanUrl(finalUrl);
|
|
316
314
|
}
|
|
317
315
|
catch (e) {
|
|
318
316
|
return cleanUrl(url);
|
|
@@ -637,28 +635,17 @@ function apply(ctx, config) {
|
|
|
637
635
|
let lastError = null;
|
|
638
636
|
for (let i = 0; i <= retryTimes; i++) {
|
|
639
637
|
try {
|
|
640
|
-
const params = { url
|
|
638
|
+
const params = { url };
|
|
641
639
|
let res;
|
|
642
640
|
if (platform === 'xiaohongshu') {
|
|
643
641
|
res = await http.post(API_CONFIG[platform], new URLSearchParams(params), {
|
|
644
|
-
timeout: config.timeout
|
|
645
|
-
headers: {
|
|
646
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
647
|
-
'Origin': 'https://api.bugpk.com',
|
|
648
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
649
|
-
'Cache-Control': 'no-cache',
|
|
650
|
-
'Pragma': 'no-cache'
|
|
651
|
-
}
|
|
642
|
+
timeout: config.timeout
|
|
652
643
|
});
|
|
653
644
|
}
|
|
654
645
|
else {
|
|
655
646
|
res = await http.get(API_CONFIG[platform], {
|
|
656
647
|
params,
|
|
657
|
-
timeout: config.timeout
|
|
658
|
-
headers: {
|
|
659
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
660
|
-
'Origin': 'https://www.baidu.com'
|
|
661
|
-
}
|
|
648
|
+
timeout: config.timeout
|
|
662
649
|
});
|
|
663
650
|
}
|
|
664
651
|
return res.data;
|
|
@@ -728,7 +715,7 @@ function apply(ctx, config) {
|
|
|
728
715
|
}
|
|
729
716
|
}
|
|
730
717
|
async function processSingleUrl(session, url) {
|
|
731
|
-
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');
|
|
732
719
|
const now = Date.now();
|
|
733
720
|
if (processed.get(hash) && now - processed.get(hash) < config.sameLinkInterval * 1000) {
|
|
734
721
|
logger.warn(`相同链接重复解析: ${url}`);
|
package/package.json
CHANGED