Skip to content

Commit

Permalink
feat: add yandex video, vk video iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
Feverqwe authored and 3y3 committed Sep 5, 2024
1 parent dbf5642 commit 6a5033a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/transform/plugins/video/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export enum VideoService {
Vine = 'vine',
Prezi = 'prezi',
Osf = 'osf',
YandexVideo = 'yandexVideo',
VkVideo = 'vkVideo',
}

export const defaults: VideoFullOptions = {
Expand All @@ -18,4 +20,6 @@ export const defaults: VideoFullOptions = {
vine: {width: 600, height: 600, embed: 'simple'},
prezi: {width: 550, height: 400},
osf: {width: '100%', height: '100%'},
yandexVideo: {width: 640, height: 390},
vkVideo: {width: 640, height: 390},
};
16 changes: 7 additions & 9 deletions src/transform/plugins/video/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Process @[vine](vineVideoID)
// Process @[prezi](preziID)
// Process @[osf](guid)
// Process @[yandexVideo](videoID)
// Process @[vkVideo](videoID)

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

return videoID === ''
? ''
: '<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item ' +
service +
'-player" type="text/html" width="' +
width +
'" height="' +
height +
'" src="' +
options.url(service, videoID, options) +
'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>';
: `<div class="embed-responsive embed-responsive-16by9"><iframe` +
` class="embed-responsive-item ${service}-player"` +
` type="text/html" width="${width}" height="${height}"` +
` src="${options.url(service, videoID, options)}"` +
`frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
};
}

Expand Down
18 changes: 18 additions & 0 deletions src/transform/plugins/video/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ export function mfrParser(url: string) {
return match ? match[1] : url;
}

const yandexVideoRegex = /^https:\/\/runtime.video.cloud.yandex.net\/player\/video\/([a-zA-Z0-9]+)/;
export function yandexVideoParser(url: string) {
const match = url.match(yandexVideoRegex);
return match ? match[1] : url;
}

const vkVideoRegex = /^https:\/\/vk.com\/video_ext\.php?(oid=[-\d]+&id=[-\d]+)/;
export function vkVideoParser(url: string) {
const match = url.match(vkVideoRegex);
return match ? match[1] : url;
}

export function parseVideoUrl(service: string, url: string): string | false {
let videoID = '';

Expand All @@ -52,6 +64,12 @@ export function parseVideoUrl(service: string, url: string): string | false {
case VideoService.Osf:
videoID = mfrParser(url);
break;
case VideoService.YandexVideo:
videoID = yandexVideoParser(url);
break;
case VideoService.VkVideo:
videoID = vkVideoParser(url);
break;
default:
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/transform/plugins/video/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type VideoServicesOptions = {
[VideoService.Vine]: {width: number; height: number; embed: 'simple' | string};
[VideoService.Prezi]: {width: number; height: number};
[VideoService.Osf]: {width: string; height: string};
[VideoService.YandexVideo]: {width: number; height: number};
[VideoService.VkVideo]: {width: number; height: number};
};

export type VideoFullOptions = VideoServicesOptions & {
Expand Down
15 changes: 9 additions & 6 deletions src/transform/plugins/video/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import type {VideoUrlFn} from './types';
export const videoUrl: VideoUrlFn = (service, videoID, options) => {
switch (service) {
case 'youtube':
return 'https://www.youtube.com/embed/' + videoID;
return `https://www.youtube.com/embed/${videoID}`;
case 'vimeo':
return 'https://player.vimeo.com/video/' + videoID;
return `https://player.vimeo.com/video/${videoID}`;
case 'vine':
return 'https://vine.co/v/' + videoID + '/embed/' + options.vine.embed;
return `https://vine.co/v/${videoID}/embed/${options.vine.embed}`;
case 'prezi':
return (
'https://prezi.com/embed/' +
videoID +
`https://prezi.com/embed/${videoID}` +
'/?bgcolor=ffffff&amp;lock_to_path=0&amp;autoplay=0&amp;autohide_ctrls=0&amp;' +
'landing_data=bHVZZmNaNDBIWnNjdEVENDRhZDFNZGNIUE43MHdLNWpsdFJLb2ZHanI5N1lQVHkxSHFxazZ0UUNCRHloSXZROHh3PT0&amp;' +
'landing_sign=1kD6c0N6aYpMUS0wxnQjxzSqZlEB8qNFdxtdjYhwSuI'
);
case 'osf':
return 'https://mfr.osf.io/render?url=https://osf.io/' + videoID + '/?action=download';
return `https://mfr.osf.io/render?url=https://osf.io/${videoID}/?action=download`;
case 'yandexVideo':
return `https://runtime.video.cloud.yandex.net/player/${videoID}`;
case 'vkVideo':
return `https://vk.com/video_ext.php?${videoID}`;
default:
return service;
}
Expand Down

0 comments on commit 6a5033a

Please sign in to comment.