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.
Files changed (2) hide show
  1. package/lib/index.js +11 -24
  2. 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.head(url, {
307
- timeout: 15000,
308
- maxRedirects: 15,
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: (status) => status >= 200 && status < 400
310
+ validateStatus: status => true
314
311
  });
315
- return cleanUrl(res.request.res?.responseUrl || url);
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, proxyurl: '' };
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-video-parser-all",
3
3
  "description": "Koishi 全平台视频解析插件,支持抖音/快手/B站/小红书/微博/今日头条/皮皮搞笑/皮皮虾/最右视频链接解析",
4
- "version": "0.7.1",
4
+ "version": "0.7.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [