mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: add youku video support
This commit is contained in:
1 file changed
+17
-34
@@ -38,14 +38,9 @@ function extractVideoParameters(url: string) {
|
|||||||
}
|
}
|
||||||
return parameterMap;
|
return parameterMap;
|
||||||
}
|
}
|
||||||
function resourceUrl(service: string, src: string, url: string, options) {
|
function resourceUrl(service: string, src: string, url: string) {
|
||||||
if (service === 'youtube') {
|
if (service === 'youtube') {
|
||||||
const parameters = extractVideoParameters(url);
|
const parameters = extractVideoParameters(url);
|
||||||
if (options.youtube.parameters) {
|
|
||||||
Object.keys(options.youtube.parameters).forEach((key) => {
|
|
||||||
parameters.set(key, options.youtube.parameters[key]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const timeParameter = parameters.get('t');
|
const timeParameter = parameters.get('t');
|
||||||
if (timeParameter !== undefined) {
|
if (timeParameter !== undefined) {
|
||||||
let startTime = 0;
|
let startTime = 0;
|
||||||
@@ -63,14 +58,19 @@ function resourceUrl(service: string, src: string, url: string, options) {
|
|||||||
parameters.delete('origin');
|
parameters.delete('origin');
|
||||||
const parameterArray = Array.from(parameters, (p) => p.join('='));
|
const parameterArray = Array.from(parameters, (p) => p.join('='));
|
||||||
const parameterPos = src.indexOf('?');
|
const parameterPos = src.indexOf('?');
|
||||||
let finalUrl = 'https://www.youtube';
|
let finalUrl = `https://www.youtube.com/embed/${parameterPos > -1 ? src.substring(0, parameterPos) : src}`;
|
||||||
if (options.youtube.nocookie || url.indexOf('youtube-nocookie.com') > -1) finalUrl += '-nocookie';
|
|
||||||
finalUrl += `.com/embed/${parameterPos > -1 ? src.substr(0, parameterPos) : src}`;
|
|
||||||
if (parameterArray.length > 0) finalUrl += `?${parameterArray.join('&')}`;
|
if (parameterArray.length > 0) finalUrl += `?${parameterArray.join('&')}`;
|
||||||
return finalUrl;
|
return finalUrl;
|
||||||
}
|
}
|
||||||
|
if (service === 'bilibili') {
|
||||||
|
if (src.startsWith('http')) src = src.split('/').pop();
|
||||||
|
if (src.toLowerCase().startsWith('av')) src = src.toLowerCase().split('av')[1];
|
||||||
|
src = src.split('?')[0];
|
||||||
|
return `//player.bilibili.com/player.html?${src.startsWith('BV') ? 'bvid' : 'aid'}=${src}&autoplay=0`;
|
||||||
|
}
|
||||||
|
if (service === 'youku') return `https://player.youku.com/embed/${src}`;
|
||||||
if (service === 'vimeo') return `https://player.vimeo.com/video/${src}`;
|
if (service === 'vimeo') return `https://player.vimeo.com/video/${src}`;
|
||||||
if (service === 'vine') return `https://vine.co/v/${src}/embed/${options.vine.embed}`;
|
if (service === 'vine') return `https://vine.co/v/${src}/embed/simple`;
|
||||||
if (service === 'prezi') {
|
if (service === 'prezi') {
|
||||||
return `https://prezi.com/embed/${src}/?bgcolor=ffffff&lock_to_path=0&autoplay=0&autohide_ctrls=0&`
|
return `https://prezi.com/embed/${src}/?bgcolor=ffffff&lock_to_path=0&autoplay=0&autohide_ctrls=0&`
|
||||||
+ 'landing_data=bHVZZmNaNDBIWnNjdEVENDRhZDFNZGNIUE43MHdLNWpsdFJLb2ZHanI5N1lQVHkxSHFxazZ0UUNCRHloSXZROHh3PT0&'
|
+ 'landing_data=bHVZZmNaNDBIWnNjdEVENDRhZDFNZGNIUE43MHdLNWpsdFJLb2ZHanI5N1lQVHkxSHFxazZ0UUNCRHloSXZROHh3PT0&'
|
||||||
@@ -80,27 +80,10 @@ function resourceUrl(service: string, src: string, url: string, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Media(md: MarkdownIt) {
|
export function Media(md: MarkdownIt) {
|
||||||
const options = {
|
const supported = ['youtube', 'vimeo', 'vine', 'prezi', 'bilibili', 'youku'];
|
||||||
url: resourceUrl,
|
|
||||||
video: resourceUrl,
|
|
||||||
youtube: { width: 640, height: 390, nocookie: false },
|
|
||||||
vimeo: { width: 500, height: 281 },
|
|
||||||
vine: { width: 600, height: 600, embed: 'simple' },
|
|
||||||
prezi: { width: 550, height: 400 },
|
|
||||||
pdf: resourceUrl,
|
|
||||||
};
|
|
||||||
md.renderer.rules.video = function tokenizeReturn(tokens, idx) {
|
md.renderer.rules.video = function tokenizeReturn(tokens, idx) {
|
||||||
let src = md.utils.escapeHtml(tokens[idx].attrGet('src'));
|
let src = md.utils.escapeHtml(tokens[idx].attrGet('src'));
|
||||||
const service = md.utils.escapeHtml(tokens[idx].attrGet('service')).toLowerCase();
|
const service = md.utils.escapeHtml(tokens[idx].attrGet('service')).toLowerCase();
|
||||||
if (service === 'bilibili') {
|
|
||||||
if (src.startsWith('http')) src = src.split('/').pop();
|
|
||||||
if (src.toLowerCase().startsWith('av')) src = src.toLowerCase().split('av')[1];
|
|
||||||
src = src.split('?')[0];
|
|
||||||
return `\
|
|
||||||
<iframe src="//player.bilibili.com/player.html?${src.startsWith('BV') ? 'bvid' : 'aid'}=${src}&autoplay=0"
|
|
||||||
scrolling="no" border="0" frameborder="no" framespacing="0" width="100%" style="min-height:500px" ${allowFullScreen}></iframe>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
if (service === 'msoffice') {
|
if (service === 'msoffice') {
|
||||||
return `\
|
return `\
|
||||||
<iframe src="https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(src)}"
|
<iframe src="https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(src)}"
|
||||||
@@ -124,12 +107,12 @@ export function Media(md: MarkdownIt) {
|
|||||||
Your browser doesn't support video tag.
|
Your browser doesn't support video tag.
|
||||||
</video>`;
|
</video>`;
|
||||||
}
|
}
|
||||||
if (options[service]?.width) {
|
if (supported.includes(service)) {
|
||||||
return `<div class="embed-responsive embed-responsive-16by9">
|
return `\
|
||||||
<iframe class="embed-responsive-item ${service}-player" type="text/html" width="${options[service].width || 640}"\
|
<iframe class="embed-responsive-item ${service}-player" type="text/html" \
|
||||||
height="${options[service].height || 390}"\
|
width="100%" style="min-height: 500px" ${allowFullScreen} \
|
||||||
src="${options.url(service, src, tokens[idx].attrGet('url'), options)}"
|
src="${resourceUrl(service, src, tokens[idx].attrGet('url'))}"
|
||||||
frameborder="0"${allowFullScreen}></iframe></div>`;
|
scrolling="no" border="0" frameborder="no" framespacing="0"></iframe>`;
|
||||||
}
|
}
|
||||||
return `<div data-${service}>${md.utils.escapeHtml(src)}</div>`;
|
return `<div data-${service}>${md.utils.escapeHtml(src)}</div>`;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user