2010-11-23 15:21:01 +00:00
|
|
|
var padmaConfig = {
|
|
|
|
'background': 'rgba(0,0,0,0.85)',
|
|
|
|
'color': '#fff',
|
2011-02-21 21:06:27 +00:00
|
|
|
'links_url': 'pad.ma/',
|
2012-02-15 09:35:45 +00:00
|
|
|
'data_url': 'http://next.pad.ma/',
|
|
|
|
'default_layers': ['transcripts', 'descriptions'],
|
2010-11-23 15:21:01 +00:00
|
|
|
};
|
|
|
|
|
2010-11-23 10:29:45 +00:00
|
|
|
(function($) {
|
|
|
|
|
2010-11-23 15:21:01 +00:00
|
|
|
var BASE_URL = padmaConfig.data_url;
|
2010-09-01 15:54:45 +00:00
|
|
|
|
|
|
|
var padmaVideo = function(videoId) {
|
|
|
|
this.id = videoId;
|
2012-02-15 09:35:45 +00:00
|
|
|
// this.videoUrl = BASE_URL + videoId + "/video.js";
|
|
|
|
// this.layersUrl = BASE_URL + videoId + "/layers.js";
|
|
|
|
// this.infoUrl = BASE_URL + videoId + "/info";
|
|
|
|
// this.hasVideoData = false;
|
|
|
|
// this.hasLayersData = false;
|
2010-09-01 15:54:45 +00:00
|
|
|
this.hasAllData = false;
|
|
|
|
this.video = {};
|
2010-11-14 01:57:18 +00:00
|
|
|
this.layers = {};
|
|
|
|
var that = this;
|
|
|
|
padmaVideo.cache.push(that);
|
2010-09-01 15:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
padmaVideo.prototype.getAllData = function(callback, data) {
|
|
|
|
var that = this;
|
|
|
|
if (!this.hasAllData) {
|
2012-02-15 09:35:45 +00:00
|
|
|
var keys = ['layers', 'title', 'duration']
|
|
|
|
var d = JSON.stringify({
|
|
|
|
'id': that.id,
|
|
|
|
'keys': keys
|
|
|
|
});
|
|
|
|
var url = BASE_URL + "api/";
|
|
|
|
$.post(url, {'action': 'get', 'data': d}, function(response) {
|
|
|
|
var v = response.data;
|
|
|
|
that.video.title = v.title;
|
|
|
|
that.video.duration = v.duration;
|
2012-02-15 12:33:47 +00:00
|
|
|
that.infoUrl = padmaConfig.data_url + that.id + "/info";
|
2012-02-15 09:35:45 +00:00
|
|
|
that.layers = flattenLayers(v.layers);
|
|
|
|
that.hasAllData = true;
|
|
|
|
that.hasLayersData = true;
|
|
|
|
that.videoSrc = that.getVideo(0, '240');
|
|
|
|
|
|
|
|
callback(that, data);
|
|
|
|
}, "json");
|
|
|
|
|
|
|
|
/*
|
2010-09-01 15:54:45 +00:00
|
|
|
$.getScript(that.videoUrl, function() {
|
|
|
|
that.video = video;
|
|
|
|
that.hasVideoData = true;
|
|
|
|
$.getScript(that.layersUrl, function() {
|
|
|
|
that.layers = layers;
|
|
|
|
that.hasLayersData = true;
|
|
|
|
that.hasAllData = true;
|
|
|
|
callback(that, data);
|
|
|
|
});
|
|
|
|
});
|
2012-02-15 09:35:45 +00:00
|
|
|
*/
|
2010-09-01 15:54:45 +00:00
|
|
|
} else {
|
|
|
|
callback(that, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//tc in npt
|
|
|
|
padmaVideo.prototype.getFrame = function(tc) {
|
2012-02-15 09:35:45 +00:00
|
|
|
tc = npt2ms(tc) / 1000
|
|
|
|
return BASE_URL + this.id + "/240p" + tc + ".jpg";
|
2010-09-01 15:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//tc in npt
|
|
|
|
padmaVideo.prototype.getVideo = function(tc, size) {
|
2012-02-15 09:35:45 +00:00
|
|
|
if (!this.hasAllData) {
|
2010-09-01 15:54:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (typeof(size) == 'undefined') {
|
2012-02-15 09:35:45 +00:00
|
|
|
size = '240';
|
2010-09-01 15:54:45 +00:00
|
|
|
}
|
2012-02-15 09:35:45 +00:00
|
|
|
return BASE_URL + this.id + "/" + size + "p.webm";
|
|
|
|
// return this.video.urls[size] + "?t=npt:" + tc;
|
2010-09-01 15:54:45 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 02:37:46 +00:00
|
|
|
|
|
|
|
padmaVideo.prototype.getDownloadLink = function(tcIn, tcOut) {
|
2012-02-15 12:33:47 +00:00
|
|
|
var inSeconds = npt2ms(tcIn) / 1000;
|
|
|
|
var outSeconds = npt2ms(tcOut) / 1000;
|
|
|
|
return this.getVideo(0, "480") + "?t=" + inSeconds + "," + outSeconds;
|
2012-02-15 09:35:45 +00:00
|
|
|
// return BASE_URL + this.id + "/download/" + tcIn + "-" + tcOut + ".ogv";
|
2010-09-01 15:54:45 +00:00
|
|
|
}
|
2011-03-14 02:37:46 +00:00
|
|
|
|
2011-02-21 21:06:27 +00:00
|
|
|
|
|
|
|
padmaVideo.prototype.getLayerVideo = function(tcIn, tcOut) {
|
|
|
|
return this.video.urls['320'] + "?t=" + tcIn + "/" + tcOut;
|
|
|
|
}
|
2010-09-01 15:54:45 +00:00
|
|
|
|
|
|
|
padmaVideo.prototype.noop = function() {
|
2010-09-01 16:14:51 +00:00
|
|
|
// console.log("I'm done:)");
|
2010-11-14 14:57:19 +00:00
|
|
|
$.noop();
|
2010-09-01 15:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
padmaVideo.prototype.getVideoData = function(callback, data) {
|
|
|
|
var that = this;
|
2010-11-14 01:57:18 +00:00
|
|
|
if (this.hasVideoData) {
|
2010-09-01 15:54:45 +00:00
|
|
|
callback(that, data);
|
2010-11-14 01:57:18 +00:00
|
|
|
} else {
|
|
|
|
$.getScript(that.videoUrl, function() {
|
|
|
|
that.video = video;
|
|
|
|
that.hasVideoData = true;
|
|
|
|
callback(that, data);
|
|
|
|
});
|
|
|
|
}
|
2010-09-01 15:54:45 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 01:57:18 +00:00
|
|
|
padmaVideo.prototype.getLayersData = function(callback, data) {
|
2010-09-01 15:54:45 +00:00
|
|
|
var that = this;
|
2010-11-14 01:57:18 +00:00
|
|
|
if (this.hasLayersData) {
|
|
|
|
callback(that, data);
|
|
|
|
} else {
|
|
|
|
$.getScript(that.layersUrl, function() {
|
|
|
|
that.layers = layers;
|
|
|
|
that.hasLayersData = true;
|
|
|
|
callback(that, data);
|
|
|
|
});
|
|
|
|
}
|
2010-09-01 15:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
padmaVideo.prototype.getLayerById = function(id) {
|
|
|
|
var that = this;
|
|
|
|
if (!this.hasLayersData) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (var i=0; i < that.layers.length; i++) {
|
|
|
|
var thisLayer = that.layers[i];
|
|
|
|
if (thisLayer.id == id) {
|
|
|
|
return thisLayer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
//timecode in ms
|
|
|
|
padmaVideo.prototype.getLayersAtTimecode = function(tc) {
|
|
|
|
var that = this;
|
|
|
|
if (!this.hasLayersData) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-11-05 22:51:50 +00:00
|
|
|
// console.log(tc);
|
2010-09-01 15:54:45 +00:00
|
|
|
var layers = [];
|
|
|
|
for (var i=0; i < that.layers.length; i++) {
|
|
|
|
var thisLayer = that.layers[i];
|
2012-02-15 09:35:45 +00:00
|
|
|
// thisLayer.time_in = thisLayer.in * 1000;
|
|
|
|
// thisLayer.time_out = thisLayer.out * 1000;
|
2010-09-01 15:54:45 +00:00
|
|
|
if (tc > thisLayer.time_in && tc < thisLayer.time_out) {
|
|
|
|
layers.push(thisLayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return layers;
|
|
|
|
}
|
2010-11-05 22:51:50 +00:00
|
|
|
|
2011-01-01 15:06:46 +00:00
|
|
|
padmaVideo.prototype.getLayerById = function(id) {
|
|
|
|
var that = this;
|
|
|
|
var id = $.trim(id);
|
|
|
|
for (var i=0; i < that.layers.length; i++) {
|
|
|
|
var thisLayer = that.layers[i];
|
|
|
|
if (thisLayer.id == id) {
|
|
|
|
return thisLayer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-15 09:35:45 +00:00
|
|
|
//convert layers format from new structure to old
|
|
|
|
function flattenLayers(layers) {
|
|
|
|
var ret = [];
|
|
|
|
for (var track in layers) {
|
|
|
|
if (layers.hasOwnProperty(track)) {
|
|
|
|
for (var i=0; i<layers[track].length; i++) {
|
|
|
|
var thisLayer = layers[track][i];
|
|
|
|
thisLayer.track = track;
|
|
|
|
thisLayer.value_html = thisLayer.value;
|
|
|
|
thisLayer.time_in = parseInt(thisLayer['in'] * 1000);
|
|
|
|
thisLayer.time_out = parseInt(thisLayer['out'] * 1000);
|
|
|
|
thisLayer.creator = thisLayer.user;
|
|
|
|
ret.push(thisLayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-05 22:51:50 +00:00
|
|
|
function filterLayersByTracks(layers, tracks) {
|
|
|
|
var matchedLayers = []
|
|
|
|
for (var i=0; i < layers.length; i++) {
|
|
|
|
var layer = layers[i];
|
|
|
|
// console.log(layer.track);
|
|
|
|
if ($.inArray(layer.track, tracks) != -1) {
|
|
|
|
matchedLayers.push(layer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matchedLayers;
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterLayersByContributors(layers, users) {
|
|
|
|
var matchedLayers = [];
|
|
|
|
for (var i=0; i < layers.length; i++) {
|
|
|
|
var layer = layers[i];
|
|
|
|
if ($.inArray(layer.contributor, users)) {
|
|
|
|
matchedLayers.push(layer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matchedLayers;
|
|
|
|
}
|
2010-11-14 01:57:18 +00:00
|
|
|
|
|
|
|
padmaVideo.cache = [];
|
|
|
|
|
|
|
|
padmaVideo.getFromCache = function(videoId) {
|
|
|
|
var cache = padmaVideo.cache;
|
|
|
|
for (var i=0; i<cache.length; i++) {
|
|
|
|
var v = cache[i];
|
|
|
|
if (v.id === videoId) {
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-11-23 10:29:45 +00:00
|
|
|
|
|
|
|
window.padmaVideo = padmaVideo;
|
|
|
|
window.filterLayersByTracks = filterLayersByTracks;
|
|
|
|
window.filterLayersByContributors = filterLayersByContributors;
|
|
|
|
|
2010-11-23 15:21:01 +00:00
|
|
|
|
|
|
|
|
2010-11-23 10:29:45 +00:00
|
|
|
})(jQuery);
|