From 14879811a51efbe5978adeea3039d341e99d9bf6 Mon Sep 17 00:00:00 2001 From: Jordan Callicoat Date: Tue, 18 Apr 2017 16:31:52 +0000 Subject: [PATCH 1/3] Make videoPlugin work for all imgur gifv videos Some gifv links on imgur.com do not have an associated webm video and only provide an mp4 video. Add two source elements with proper mimetypes for both types of video. The video player will fall back to the secondary source if the first cannot be loaded (due to 404) Example: Trying to load the webm version of this video http://i.imgur.com/i7D4GRb.webm will result in a 302 redirect to the gifv url, which tries to load an HTML document. This will cause our video player to reject the document as an invalid video format (text/html); on some videos it will simply 404. The mp4 version is available and our player will fall back to that. --- js/plugins.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index dc02775..92d7d37 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -339,17 +339,27 @@ plugins.factory('userPlugins', function() { */ var videoPlugin = new UrlPlugin('video', function(url) { if (url.match(/\.(3gp|avi|flv|gifv|mkv|mp4|ogv|webm|wmv)\b/i)) { - if (url.match(/^http:\/\/(i\.)?imgur\.com\//i)) { - // remove protocol specification to load over https if used by g-b - url = url.replace(/\.(gifv)\b/i, ".webm"); - } return function() { - var element = this.getElement(); + var element = this.getElement(), src; var velement = angular.element('') .addClass('embed') - .attr('width', '560') - .append(angular.element('') - .attr('src', url)); + .attr('width', '560'); + // imgur doesn't always have webm for gifv so add sources for webm and mp4 + if (url.match(/^http:\/\/(i\.)?imgur\.com\//i) && + url.indexOf('.gifv') > -1) { + src = angular.element('') + .attr('src', url.replace(/\.gifv\b/i, ".webm")) + .attr('type', 'video/webm'); + velement.append(src); + src = angular.element('') + .attr('src', url.replace(/\.gifv\b/i, ".mp4")) + .attr('type', 'video/mp4'); + velement.append(src); + } else { + src = angular.element('') + .attr('src', url); + velement.append(src); + } element.innerHTML = velement.prop('outerHTML'); }; } From 6d7de0c7462ddc88dc1f381d713176760c0b61cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Wed, 19 Apr 2017 14:01:57 +0200 Subject: [PATCH 2/3] imgur: force https, simplify regex --- js/plugins.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index 92d7d37..918ad97 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -339,14 +339,17 @@ plugins.factory('userPlugins', function() { */ var videoPlugin = new UrlPlugin('video', function(url) { if (url.match(/\.(3gp|avi|flv|gifv|mkv|mp4|ogv|webm|wmv)\b/i)) { + if (url.match(/^http:\/\/(i\.)?imgur\.com\//i)) { + // imgur: force https + url = url.replace(/^http:/, "https:"); + } return function() { var element = this.getElement(), src; var velement = angular.element('') .addClass('embed') .attr('width', '560'); // imgur doesn't always have webm for gifv so add sources for webm and mp4 - if (url.match(/^http:\/\/(i\.)?imgur\.com\//i) && - url.indexOf('.gifv') > -1) { + if (url.match(/^https:\/\/(i\.)?imgur\.com\/.*\.gifv/i)) { src = angular.element('') .attr('src', url.replace(/\.gifv\b/i, ".webm")) .attr('type', 'video/webm'); From 8a230e9bf34ce2a1ae680693ec3e9d0a61b03b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Wed, 19 Apr 2017 14:05:37 +0200 Subject: [PATCH 3/3] imgur: force https (2), fix comment --- js/plugins.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index 918ad97..2140d3f 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -281,8 +281,8 @@ plugins.factory('userPlugins', function() { if (url.indexOf("^https?://fukung.net/v/") != -1) { url = url.replace(/.*\//, "http://media.fukung.net/imgs/"); } else if (url.match(/^http:\/\/(i\.)?imgur\.com\//i)) { - // remove protocol specification to load over https if used by g-b - url = url.replace(/http:/, "https:"); + // imgur: always use https. avoids mixed content warnings + url = url.replace(/^http:/, "https:"); } else if (url.match(/^https:\/\/www\.dropbox\.com\/s\/[a-z0-9]+\//i)) { // Dropbox requires a get parameter, dl=1 var dbox_url = document.createElement("a"); @@ -340,7 +340,7 @@ plugins.factory('userPlugins', function() { var videoPlugin = new UrlPlugin('video', function(url) { if (url.match(/\.(3gp|avi|flv|gifv|mkv|mp4|ogv|webm|wmv)\b/i)) { if (url.match(/^http:\/\/(i\.)?imgur\.com\//i)) { - // imgur: force https + // imgur: always use https. avoids mixed content warnings url = url.replace(/^http:/, "https:"); } return function() {