From 8f03bc59811f8f5e2da2685c2bccdfcb48eadb7f Mon Sep 17 00:00:00 2001 From: biati-digital Date: Tue, 8 Mar 2022 14:23:28 -0600 Subject: [PATCH] Added support for videos without extension --- src/js/core/slide-parser.js | 1 + src/js/slides/video.js | 63 +++++++++---------------------------- 2 files changed, 15 insertions(+), 49 deletions(-) diff --git a/src/js/core/slide-parser.js b/src/js/core/slide-parser.js index 16dcd52..6a73e46 100644 --- a/src/js/core/slide-parser.js +++ b/src/js/core/slide-parser.js @@ -8,6 +8,7 @@ export default class SlideConfigParser { srcset: '', title: '', type: '', + videoProvider: '', description: '', alt: '', descPosition: 'bottom', diff --git a/src/js/slides/video.js b/src/js/slides/video.js index 995ecc0..47582e7 100644 --- a/src/js/slides/video.js +++ b/src/js/slides/video.js @@ -24,8 +24,7 @@ export default function slideVideo(slide, data, index, callback) { let url = data.href; let protocol = location.protocol.replace(':', ''); - let videoSource = ''; - let embedID = ''; + let provider = data?.videoProvider; let customPlaceholder = false; if (protocol == 'file') { @@ -35,22 +34,22 @@ export default function slideVideo(slide, data, index, callback) { injectAssets(this.settings.plyr.js, 'Plyr', () => { // Set vimeo videos - if (url.match(/vimeo\.com\/([0-9]*)/)) { - const vimeoID = /vimeo.*\/(\d+)/i.exec(url); - videoSource = 'vimeo'; - embedID = vimeoID[1]; + if (!provider && url.match(/vimeo\.com\/([0-9]*)/)) { + provider = 'vimeo'; } // Set youtube videos - if (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) || url.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/) || url.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/)) { - const youtubeID = getYoutubeID(url); - videoSource = 'youtube'; - embedID = youtubeID; + if ( + !provider && + (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) || url.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/) || url.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/)) + ) { + provider = 'youtube'; } // Set local videos - if (url.match(/\.(mp4|ogg|webm|mov)$/) !== null) { - videoSource = 'local'; + // if no provider, default to local + if (provider === 'local' || !provider) { + provider = 'local'; let html = ''; customPlaceholder = createHTML(html); } // prettier-ignore - const placeholder = customPlaceholder ? customPlaceholder : createHTML(`
`); + const placeholder = customPlaceholder ? customPlaceholder : createHTML(`
`); - addClass(videoWrapper, `${videoSource}-video gvideo`); + addClass(videoWrapper, `${provider}-video gvideo`); videoWrapper.appendChild(placeholder); videoWrapper.setAttribute('data-id', videoID); videoWrapper.setAttribute('data-index', index); @@ -110,24 +93,6 @@ export default function slideVideo(slide, data, index, callback) { }); } -/** - * Get youtube ID - * - * @param {string} url - * @returns {string} video id - */ -function getYoutubeID(url) { - let videoID = ''; - url = url.replace(/(>|<)/gi, '').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/); - if (url[2] !== undefined) { - videoID = url[2].split(/[^0-9a-z_\-]/i); - videoID = videoID[0]; - } else { - videoID = url; - } - return videoID; -} - /** * Handle fullscreen *