Skip to content

Commit ff06a10

Browse files
committed
api/processing/url: improve vk url parsing
1 parent 997b06e commit ff06a10

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

api/src/processing/service-config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,13 @@ export const services = {
186186
patterns: [
187187
"video:ownerId_:videoId",
188188
"clip:ownerId_:videoId",
189-
"clips:duplicate?z=clip:ownerId_:videoId",
190-
"videos:duplicate?z=video:ownerId_:videoId",
191189
"video:ownerId_:videoId_:accessKey",
192190
"clip:ownerId_:videoId_:accessKey",
193-
"clips:duplicate?z=clip:ownerId_:videoId_:accessKey",
194-
"videos:duplicate?z=video:ownerId_:videoId_:accessKey"
191+
192+
// links with a duplicate author id and/or zipper query param
193+
"clips:duplicateId",
194+
"videos:duplicateId",
195+
"search/video"
195196
],
196197
subdomains: ["m"],
197198
altDomains: ["vkvideo.ru", "vk.ru"],

api/src/processing/url.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function aliasURL(url) {
1717
if (url.pathname.startsWith('/live/') || url.pathname.startsWith('/shorts/')) {
1818
url.pathname = '/watch';
1919
// parts := ['', 'live' || 'shorts', id, ...rest]
20-
url.search = `?v=${encodeURIComponent(parts[2])}`
20+
url.search = `?v=${encodeURIComponent(parts[2])}`;
2121
}
2222
break;
2323

@@ -61,23 +61,23 @@ function aliasURL(url) {
6161

6262
case "b23":
6363
if (url.hostname === 'b23.tv' && parts.length === 2) {
64-
url = new URL(`https://bilibili.com/_shortLink/${parts[1]}`)
64+
url = new URL(`https://bilibili.com/_shortLink/${parts[1]}`);
6565
}
6666
break;
6767

6868
case "dai":
6969
if (url.hostname === 'dai.ly' && parts.length === 2) {
70-
url = new URL(`https://dailymotion.com/video/${parts[1]}`)
70+
url = new URL(`https://dailymotion.com/video/${parts[1]}`);
7171
}
7272
break;
7373

7474
case "facebook":
7575
case "fb":
7676
if (url.searchParams.get('v')) {
77-
url = new URL(`https://web.facebook.com/user/videos/${url.searchParams.get('v')}`)
77+
url = new URL(`https://web.facebook.com/user/videos/${url.searchParams.get('v')}`);
7878
}
7979
if (url.hostname === 'fb.watch') {
80-
url = new URL(`https://web.facebook.com/_shortLink/${parts[1]}`)
80+
url = new URL(`https://web.facebook.com/_shortLink/${parts[1]}`);
8181
}
8282
break;
8383

@@ -92,6 +92,9 @@ function aliasURL(url) {
9292
if (services.vk.altDomains.includes(url.hostname)) {
9393
url.hostname = 'vk.com';
9494
}
95+
if (url.searchParams.get('z')) {
96+
url = new URL(`https://vk.com/${url.searchParams.get('z')}`);
97+
}
9598
break;
9699

97100
case "xhslink":
@@ -106,7 +109,7 @@ function aliasURL(url) {
106109
url.pathname = `/share/${idPart.slice(-32)}`;
107110
}
108111
break;
109-
112+
110113
case "redd":
111114
/* reddit short video links can be treated by changing https://v.redd.it/<id>
112115
to https://reddit.com/video/<id>.*/

0 commit comments

Comments
 (0)