Skip to content

Commit 6a5033a

Browse files
Feverqwe3y3
authored andcommitted
feat: add yandex video, vk video iframes
1 parent dbf5642 commit 6a5033a

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

src/transform/plugins/video/const.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export enum VideoService {
99
Vine = 'vine',
1010
Prezi = 'prezi',
1111
Osf = 'osf',
12+
YandexVideo = 'yandexVideo',
13+
VkVideo = 'vkVideo',
1214
}
1315

1416
export const defaults: VideoFullOptions = {
@@ -18,4 +20,6 @@ export const defaults: VideoFullOptions = {
1820
vine: {width: 600, height: 600, embed: 'simple'},
1921
prezi: {width: 550, height: 400},
2022
osf: {width: '100%', height: '100%'},
23+
yandexVideo: {width: 640, height: 390},
24+
vkVideo: {width: 640, height: 390},
2125
};

src/transform/plugins/video/index.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Process @[vine](vineVideoID)
44
// Process @[prezi](preziID)
55
// Process @[osf](guid)
6+
// Process @[yandexVideo](videoID)
7+
// Process @[vkVideo](videoID)
68

79
import type MarkdownIt from 'markdown-it';
810
// eslint-disable-next-line no-duplicate-imports
@@ -69,15 +71,11 @@ function tokenizeVideo(md: MarkdownIt, options: VideoFullOptions): Renderer.Rend
6971

7072
return videoID === ''
7173
? ''
72-
: '<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item ' +
73-
service +
74-
'-player" type="text/html" width="' +
75-
width +
76-
'" height="' +
77-
height +
78-
'" src="' +
79-
options.url(service, videoID, options) +
80-
'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>';
74+
: `<div class="embed-responsive embed-responsive-16by9"><iframe` +
75+
` class="embed-responsive-item ${service}-player"` +
76+
` type="text/html" width="${width}" height="${height}"` +
77+
` src="${options.url(service, videoID, options)}"` +
78+
`frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
8179
};
8280
}
8381

src/transform/plugins/video/parsers.ts

+18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ export function mfrParser(url: string) {
3333
return match ? match[1] : url;
3434
}
3535

36+
const yandexVideoRegex = /^https:\/\/runtime.video.cloud.yandex.net\/player\/video\/([a-zA-Z0-9]+)/;
37+
export function yandexVideoParser(url: string) {
38+
const match = url.match(yandexVideoRegex);
39+
return match ? match[1] : url;
40+
}
41+
42+
const vkVideoRegex = /^https:\/\/vk.com\/video_ext\.php?(oid=[-\d]+&id=[-\d]+)/;
43+
export function vkVideoParser(url: string) {
44+
const match = url.match(vkVideoRegex);
45+
return match ? match[1] : url;
46+
}
47+
3648
export function parseVideoUrl(service: string, url: string): string | false {
3749
let videoID = '';
3850

@@ -52,6 +64,12 @@ export function parseVideoUrl(service: string, url: string): string | false {
5264
case VideoService.Osf:
5365
videoID = mfrParser(url);
5466
break;
67+
case VideoService.YandexVideo:
68+
videoID = yandexVideoParser(url);
69+
break;
70+
case VideoService.VkVideo:
71+
videoID = vkVideoParser(url);
72+
break;
5573
default:
5674
return false;
5775
}

src/transform/plugins/video/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export type VideoServicesOptions = {
1212
[VideoService.Vine]: {width: number; height: number; embed: 'simple' | string};
1313
[VideoService.Prezi]: {width: number; height: number};
1414
[VideoService.Osf]: {width: string; height: string};
15+
[VideoService.YandexVideo]: {width: number; height: number};
16+
[VideoService.VkVideo]: {width: number; height: number};
1517
};
1618

1719
export type VideoFullOptions = VideoServicesOptions & {

src/transform/plugins/video/utils.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ import type {VideoUrlFn} from './types';
33
export const videoUrl: VideoUrlFn = (service, videoID, options) => {
44
switch (service) {
55
case 'youtube':
6-
return 'https://www.youtube.com/embed/' + videoID;
6+
return `https://www.youtube.com/embed/${videoID}`;
77
case 'vimeo':
8-
return 'https://player.vimeo.com/video/' + videoID;
8+
return `https://player.vimeo.com/video/${videoID}`;
99
case 'vine':
10-
return 'https://vine.co/v/' + videoID + '/embed/' + options.vine.embed;
10+
return `https://vine.co/v/${videoID}/embed/${options.vine.embed}`;
1111
case 'prezi':
1212
return (
13-
'https://prezi.com/embed/' +
14-
videoID +
13+
`https://prezi.com/embed/${videoID}` +
1514
'/?bgcolor=ffffff&amp;lock_to_path=0&amp;autoplay=0&amp;autohide_ctrls=0&amp;' +
1615
'landing_data=bHVZZmNaNDBIWnNjdEVENDRhZDFNZGNIUE43MHdLNWpsdFJLb2ZHanI5N1lQVHkxSHFxazZ0UUNCRHloSXZROHh3PT0&amp;' +
1716
'landing_sign=1kD6c0N6aYpMUS0wxnQjxzSqZlEB8qNFdxtdjYhwSuI'
1817
);
1918
case 'osf':
20-
return 'https://mfr.osf.io/render?url=https://osf.io/' + videoID + '/?action=download';
19+
return `https://mfr.osf.io/render?url=https://osf.io/${videoID}/?action=download`;
20+
case 'yandexVideo':
21+
return `https://runtime.video.cloud.yandex.net/player/${videoID}`;
22+
case 'vkVideo':
23+
return `https://vk.com/video_ext.php?${videoID}`;
2124
default:
2225
return service;
2326
}

0 commit comments

Comments
 (0)