Skip to content
This repository has been archived by the owner on May 21, 2018. It is now read-only.

Feature/video substitution #106

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
94 changes: 90 additions & 4 deletions PopcornEditor/src/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,96 @@ function init() {
resizeHandler.resize();
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't these two if clauses be merged into one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, done: fcd7913


var id = config.savedDataUrl.split('=').pop();
var url = "https://archive.org/download/" + id + "/" + id + ".mp4"
var thumb = "https://archive.org/download/" + id + "/format=Thumbnail";

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"
}
]
}, {
"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) {
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 );
Expand Down Expand Up @@ -691,7 +777,7 @@ function init() {
embedInfo.parentNode.removeChild( embedInfo );
}

}); // end Project.load() call
})}); // end Project.load() call



Expand Down Expand Up @@ -754,15 +840,15 @@ 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.
if ( location.href.match(/^http:\/\/(.*)archive.org\/pop\//) ){
location.href = location.href.replace(/^http:\/\//, 'https://');
return;
}

if ( typeof require === "undefined" ) {
var rscript = document.createElement( "script" );
rscript.onload = function() {
Expand Down