From ff06a10b5cbd6cb4fb88f3dc338f9dc51f8614d0 Mon Sep 17 00:00:00 2001 From: wukko Date: Tue, 24 Jun 2025 17:21:32 +0600 Subject: [PATCH] api/processing/url: improve vk url parsing --- api/src/processing/service-config.js | 9 +++++---- api/src/processing/url.js | 15 +++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/api/src/processing/service-config.js b/api/src/processing/service-config.js index 1c77c7bb..662b39b3 100644 --- a/api/src/processing/service-config.js +++ b/api/src/processing/service-config.js @@ -186,12 +186,13 @@ export const services = { patterns: [ "video:ownerId_:videoId", "clip:ownerId_:videoId", - "clips:duplicate?z=clip:ownerId_:videoId", - "videos:duplicate?z=video:ownerId_:videoId", "video:ownerId_:videoId_:accessKey", "clip:ownerId_:videoId_:accessKey", - "clips:duplicate?z=clip:ownerId_:videoId_:accessKey", - "videos:duplicate?z=video:ownerId_:videoId_:accessKey" + + // links with a duplicate author id and/or zipper query param + "clips:duplicateId", + "videos:duplicateId", + "search/video" ], subdomains: ["m"], altDomains: ["vkvideo.ru", "vk.ru"], diff --git a/api/src/processing/url.js b/api/src/processing/url.js index 86c333f6..5bb690e6 100644 --- a/api/src/processing/url.js +++ b/api/src/processing/url.js @@ -17,7 +17,7 @@ function aliasURL(url) { if (url.pathname.startsWith('/live/') || url.pathname.startsWith('/shorts/')) { url.pathname = '/watch'; // parts := ['', 'live' || 'shorts', id, ...rest] - url.search = `?v=${encodeURIComponent(parts[2])}` + url.search = `?v=${encodeURIComponent(parts[2])}`; } break; @@ -61,23 +61,23 @@ function aliasURL(url) { case "b23": if (url.hostname === 'b23.tv' && parts.length === 2) { - url = new URL(`https://bilibili.com/_shortLink/${parts[1]}`) + url = new URL(`https://bilibili.com/_shortLink/${parts[1]}`); } break; case "dai": if (url.hostname === 'dai.ly' && parts.length === 2) { - url = new URL(`https://dailymotion.com/video/${parts[1]}`) + url = new URL(`https://dailymotion.com/video/${parts[1]}`); } break; case "facebook": case "fb": if (url.searchParams.get('v')) { - url = new URL(`https://web.facebook.com/user/videos/${url.searchParams.get('v')}`) + url = new URL(`https://web.facebook.com/user/videos/${url.searchParams.get('v')}`); } if (url.hostname === 'fb.watch') { - url = new URL(`https://web.facebook.com/_shortLink/${parts[1]}`) + url = new URL(`https://web.facebook.com/_shortLink/${parts[1]}`); } break; @@ -92,6 +92,9 @@ function aliasURL(url) { if (services.vk.altDomains.includes(url.hostname)) { url.hostname = 'vk.com'; } + if (url.searchParams.get('z')) { + url = new URL(`https://vk.com/${url.searchParams.get('z')}`); + } break; case "xhslink": @@ -106,7 +109,7 @@ function aliasURL(url) { url.pathname = `/share/${idPart.slice(-32)}`; } break; - + case "redd": /* reddit short video links can be treated by changing https://v.redd.it/ to https://reddit.com/video/.*/