var BASE_URL = "http://pad.ma/"; var padmaVideo = function(videoId) { this.id = videoId; this.videoUrl = BASE_URL + videoId + "/video.js"; this.layersUrl = BASE_URL + videoId + "/layers.js"; this.hasVideoData = false; this.hasLayersData = false; this.hasAllData = false; this.video = {}; this.layers = {}; } padmaVideo.prototype.getAllData = function(callback, data) { var that = this; if (!this.hasAllData) { $.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); }); }); } else { callback(that, data); } } //tc in npt padmaVideo.prototype.getFrame = function(tc) { return BASE_URL + this.id + "/frame/" + tc + ".jpg"; } //tc in npt padmaVideo.prototype.getVideo = function(tc, size) { if (!this.hasVideoData) { return false; } if (typeof(size) == 'undefined') { size = '128'; } return this.video.urls[size] + "?t=npt:" + tc; } padmaVideo.prototype.getLayerVideo = function(tcIn, tcOut) { return BASE_URL + this.id + "/download/" + tcIn + "-" + tcOut + ".ogv"; } padmaVideo.prototype.noop = function() { // console.log("I'm done:)"); // $.noop(); } padmaVideo.prototype.getVideoData = function(callback, data) { var that = this; $.getScript(that.videoUrl, function() { that.video = video; that.hasVideoData = true; callback(that, data); }); } padmaVideo.prototype.getLayersData = function() { var that = this; $.getScript(layersUrl, function() { that.layers = layers; that.hasLayersData = true; }); } 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; } // console.log(tc); var layers = []; for (var i=0; i < that.layers.length; i++) { var thisLayer = that.layers[i]; if (tc > thisLayer.time_in && tc < thisLayer.time_out) { layers.push(thisLayer); } } return layers; } 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; }