From 2d4b0b8259153940c7da260f78dceac9bd96087c Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Thu, 25 Feb 2021 11:19:26 +0100 Subject: [PATCH] Fetch youtube videoid from url --- api/js/etemplate/et2_widget_video.js | 4 ++-- api/js/etemplate/et2_widget_video.ts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/js/etemplate/et2_widget_video.js b/api/js/etemplate/et2_widget_video.js index 8f639d00f3..4fb2825c3e 100644 --- a/api/js/etemplate/et2_widget_video.js +++ b/api/js/etemplate/et2_widget_video.js @@ -24,7 +24,6 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.et2_video = void 0; /*egw:uses /vendor/bower-asset/jquery/dist/jquery.js; et2_core_interfaces; @@ -135,7 +134,7 @@ var et2_video = /** @class */ (function (_super) { 'iv_load_policy': 0, 'cc_load_policy': 0 }, - videoId: _value.split('v=')[1], + videoId: _value.match(et2_video.youtubeRegexp)[4], events: { 'onReady': jQuery.proxy(self._onReady, self), 'onStateChange': jQuery.proxy(self._onStateChangeYoutube, self) @@ -417,6 +416,7 @@ var et2_video = /** @class */ (function (_super) { * @private */ et2_video.youtubePrefixId = "frame-"; + et2_video.youtubeRegexp = new RegExp(/^https:\/\/((www\.|m\.)?youtube(-nocookie)?\.com|youtu\.be)\/.*(?:\/|%3D|v=|vi=)([0-9A-z-_]{11})(?:[%#?&]|$)/m); return et2_video; }(et2_core_baseWidget_1.et2_baseWidget)); exports.et2_video = et2_video; diff --git a/api/js/etemplate/et2_widget_video.ts b/api/js/etemplate/et2_widget_video.ts index e9373c47d9..1b7aaa90c6 100644 --- a/api/js/etemplate/et2_widget_video.ts +++ b/api/js/etemplate/et2_widget_video.ts @@ -136,6 +136,9 @@ export class et2_video extends et2_baseWidget implements et2_IDOMNode * @private */ private static youtubePrefixId : string = "frame-"; + + private static youtubeRegexp: RegExp = new RegExp(/^https:\/\/((www\.|m\.)?youtube(-nocookie)?\.com|youtu\.be)\/.*(?:\/|%3D|v=|vi=)([0-9A-z-_]{11})(?:[%#?&]|$)/m); + constructor(_parent, _attrs? : WidgetConfig, _child? : object) { super(_parent, _attrs, ClassWithAttributes.extendAttributes(et2_video._attributes, _child || {})); @@ -219,7 +222,7 @@ export class et2_video extends et2_baseWidget implements et2_IDOMNode 'iv_load_policy': 0, 'cc_load_policy': 0 }, - videoId: _value.split('v=')[1], //TODO get youtube video id + videoId: _value.match(et2_video.youtubeRegexp)[4], events: { 'onReady': jQuery.proxy(self._onReady, self), 'onStateChange': jQuery.proxy(self._onStateChangeYoutube, self)