From 594f620a325d435fddfce3e5a31341635b05072f Mon Sep 17 00:00:00 2001 From: Laurian Gridinoc Date: Mon, 26 Sep 2016 23:35:06 +0100 Subject: [PATCH 1/5] json preprocessing: HTTP HEAD on a video URL, if found replaces tracks with single video --- PopcornEditor/src/embed.js | 58 +++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/PopcornEditor/src/embed.js b/PopcornEditor/src/embed.js index b7ca8cb..64d11d6 100644 --- a/PopcornEditor/src/embed.js +++ b/PopcornEditor/src/embed.js @@ -478,10 +478,60 @@ function init() { resizeHandler.resize(); window.addEventListener( "resize", resizeHandler.resize ); + function preprocess(json, callback) { + if (!video) return callback(json); + + var id = config.savedDataUrl.split('/').pop(); + var url = "_test_/" + id + ".mp4"; + + jQuery.ajax({ + type: "HEAD", + async: true, + url: url, + }).done(function(message, text, jqXHR) { + json.media[0].tracks = [{ + "name": "", + "id": "0", + "order": 0, + "trackEvents": [ + { + "id": "PPAP", + "type": "sequencer", + "popcornOptions": { + "source": [ url ], + "start": 0, + "end": json.media[0].duration, + "from": 0, + "duration": json.media[0].duration, + "target": "video-container", + "fallback": [ "" ], + "zindex": 997, + "id": "PPAP", + "width": 100, + "height": 100, + "top": 0, + "left": 0, + "volume": 100, + "hidden": false, + "mute": false, + "contentType": "", + "type": "", + "denied": false + }, + "track": "0", + "name": "PPAP0" + } + ] + }]; + callback(json); + }).error(function(jqXHR, textStatus, errorThrown) { + callback(json); + }); + } // parse the savedDataUrl (to JSON) and then invoke the 2nd param (closure / anonymous function) // with the parsed project JSON - Project.load( config.savedDataUrl, function( json ){ + Project.load( config.savedDataUrl, function(json) { preprocess(json, function(json) { Controls.create( "controls", { onShareClick: function() { shareClick( popcorn ); @@ -691,7 +741,7 @@ function init() { embedInfo.parentNode.removeChild( embedInfo ); } - }); // end Project.load() call + })}); // end Project.load() call @@ -754,7 +804,7 @@ function init() { document.addEventListener( "DOMContentLoaded", function() { // Source tree case vs. require-built case. - + // if a user comes to http://archive.org/pop // we need to auto-redirect them to https://archive.org/pop // due to CORS issues, etc. @@ -762,7 +812,7 @@ document.addEventListener( "DOMContentLoaded", function() { location.href = location.href.replace(/^http:\/\//, 'https://'); return; } - + if ( typeof require === "undefined" ) { var rscript = document.createElement( "script" ); rscript.onload = function() { From 2fbed90036de10b8868c2c780b9ab0391112862c Mon Sep 17 00:00:00 2001 From: Laurian Gridinoc Date: Tue, 27 Sep 2016 00:11:46 +0100 Subject: [PATCH 2/5] archive.org paths for video and thumb, thumb track --- PopcornEditor/src/embed.js | 39 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/PopcornEditor/src/embed.js b/PopcornEditor/src/embed.js index 64d11d6..cb3f209 100644 --- a/PopcornEditor/src/embed.js +++ b/PopcornEditor/src/embed.js @@ -479,10 +479,11 @@ function init() { window.addEventListener( "resize", resizeHandler.resize ); function preprocess(json, callback) { - if (!video) return callback(json); + if (!json || !json.media) return callback(json); var id = config.savedDataUrl.split('/').pop(); - var url = "_test_/" + id + ".mp4"; + var url = "https://archive.org/download/" + id + "/" + id + ".mp4" + var thumb = "https://archive.org/download/" + id + "/format=Thumbnail"; jQuery.ajax({ type: "HEAD", @@ -522,6 +523,40 @@ function init() { "name": "PPAP0" } ] + }, { + "name": "", + "id": "1", + "order": 1, + "trackEvents": [ + { + "id": "PPAP1", + "type": "image", + "popcornOptions": { + "start": 0, + "end": 0.2, + "target": "video-container", + "src": thumb, + "linkSrc": "", + "tags": "", + "photosetId": "", + "count": 3, + "width": 100, + "height": 100, + "top": 0, + "left": 0, + "innerTop": 0, + "innerLeft": 0, + "innerWidth": 0, + "innerHeight": 0, + "title": "", + "transition": "popcorn-fade", + "zindex": 990, + "id": "PPAP1" + }, + "track": "1", + "name": "PPAP1" + } + ] }]; callback(json); }).error(function(jqXHR, textStatus, errorThrown) { From 1e712cbf966eeb5a46166335bb7c2693c598ede2 Mon Sep 17 00:00:00 2001 From: Laurian Gridinoc Date: Tue, 27 Sep 2016 00:27:24 +0100 Subject: [PATCH 3/5] sketchy parsing/split of the id --- PopcornEditor/src/embed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PopcornEditor/src/embed.js b/PopcornEditor/src/embed.js index cb3f209..e00c1ba 100644 --- a/PopcornEditor/src/embed.js +++ b/PopcornEditor/src/embed.js @@ -481,7 +481,7 @@ function init() { function preprocess(json, callback) { if (!json || !json.media) return callback(json); - var id = config.savedDataUrl.split('/').pop(); + var id = config.savedDataUrl.split('=').pop(); var url = "https://archive.org/download/" + id + "/" + id + ".mp4" var thumb = "https://archive.org/download/" + id + "/format=Thumbnail"; From 512667fd360a5a2f7d3e858825959640702d4652 Mon Sep 17 00:00:00 2001 From: Laurian Gridinoc Date: Tue, 27 Sep 2016 08:24:52 +0100 Subject: [PATCH 4/5] well, do this magic only with EDL from IA --- PopcornEditor/src/embed.js | 1 + 1 file changed, 1 insertion(+) diff --git a/PopcornEditor/src/embed.js b/PopcornEditor/src/embed.js index e00c1ba..920dcc1 100644 --- a/PopcornEditor/src/embed.js +++ b/PopcornEditor/src/embed.js @@ -480,6 +480,7 @@ function init() { function preprocess(json, callback) { if (!json || !json.media) return callback(json); + if (!config.savedDataUrl.startsWith('https://archive.org')) return callback(json); var id = config.savedDataUrl.split('=').pop(); var url = "https://archive.org/download/" + id + "/" + id + ".mp4" From fcd7913c1457dd9ac2edbb0103ef2d236f57e338 Mon Sep 17 00:00:00 2001 From: Laurian Gridinoc Date: Sun, 19 Feb 2017 17:56:24 +0000 Subject: [PATCH 5/5] merging if clauses https://github.com/mozilla/popcorn-editor/pull/106#pullrequestreview-225 27676 --- PopcornEditor/src/embed.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PopcornEditor/src/embed.js b/PopcornEditor/src/embed.js index 920dcc1..334502a 100644 --- a/PopcornEditor/src/embed.js +++ b/PopcornEditor/src/embed.js @@ -479,8 +479,7 @@ function init() { window.addEventListener( "resize", resizeHandler.resize ); function preprocess(json, callback) { - if (!json || !json.media) return callback(json); - if (!config.savedDataUrl.startsWith('https://archive.org')) return callback(json); + if (!json || !json.media || !config.savedDataUrl.startsWith('https://archive.org')) return callback(json); var id = config.savedDataUrl.split('=').pop(); var url = "https://archive.org/download/" + id + "/" + id + ".mp4"