Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions funnel/assets/js/utils/embedvideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ const Video = {
*/
getVideoTypeAndId(url) {
const regexMatch = url.match(
/(http:|https:|)\/\/(player.|www.)?(y2u\.be|vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|live\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(&\S+)?/
/(http:|https:|)\/\/(player.|www.)?(?<service>y2u\.be|vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|live\/|watch\?v=|v\/)?(?<videoId>[A-Za-z0-9._%-]*)(&\S+)?(\?h=(?<paramId>[^&]+))?/
);
let type = '';
if (regexMatch && regexMatch.length > 5) {
if (regexMatch[3].indexOf('youtu') > -1 || regexMatch[3].indexOf('y2u') > -1) {
if (
regexMatch.groups.service.indexOf('youtu') > -1 ||
regexMatch.groups.service.indexOf('y2u') > -1
) {
type = 'youtube';
} else if (regexMatch[3].indexOf('vimeo') > -1) {
} else if (regexMatch.groups.service.indexOf('vimeo') > -1) {
type = 'vimeo';
return {
type,
videoId: regexMatch.groups.videoId,
paramId: regexMatch.groups.paramId,
};
}
return {
type,
Expand All @@ -29,11 +37,13 @@ const Video = {
},
embedIframe(videoWrapper, videoUrl) {
let videoEmbedUrl = '';
const { type, videoId } = this.getVideoTypeAndId(videoUrl);
const { type, videoId, paramId } = this.getVideoTypeAndId(videoUrl);
if (type === 'youtube') {
videoEmbedUrl = `<iframe src='//www.youtube.com/embed/${videoId}' frameborder='0' allowfullscreen></iframe>`;
} else if (type === 'vimeo') {
videoEmbedUrl = `<iframe src='https://player.vimeo.com/video/${videoId}' frameborder='0' allowfullscreen></iframe>`;
videoEmbedUrl = `<iframe src='https://player.vimeo.com/video/${videoId}${
paramId ? `?h=${paramId}` : ''
}' frameborder='0' allowfullscreen></iframe>`;
}
if (videoEmbedUrl) {
videoWrapper.innerHTML = videoEmbedUrl;
Expand Down
1 change: 1 addition & 0 deletions funnel/forms/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class ProjectLivestreamForm(forms.Form):
'y2u.be',
'www.vimeo.com',
'vimeo.com',
'player.vimeo.com',
),
message_schemes=__("A https:// URL is required"),
message_domains=__("Livestream must be on YouTube or Vimeo"),
Expand Down