Skip to content

best way to save what you love

api/processing/url: improve vk url parsing

wukkoff06a10b5cbd
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/<id>
to https://reddit.com/video/<id>.*/