From d94b749eac13fd353ca8bb8405ea9a0e2b38d00d Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 15 Feb 2012 15:05:45 +0530 Subject: [PATCH] moving to next.pad.ma --- padma.layers.js | 69 ++++++++++++++++++++++++++++++++++++++++--------- padma.links.js | 8 +++--- utils.js | 26 +++++++++---------- 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/padma.layers.js b/padma.layers.js index a3227c2..06ab62c 100644 --- a/padma.layers.js +++ b/padma.layers.js @@ -2,8 +2,8 @@ var padmaConfig = { 'background': 'rgba(0,0,0,0.85)', 'color': '#fff', 'links_url': 'pad.ma/', - 'data_url': 'http://pad.ma/', - 'default_layers': ['transcript', 'description'], + 'data_url': 'http://next.pad.ma/', + 'default_layers': ['transcripts', 'descriptions'], }; (function($) { @@ -12,11 +12,11 @@ var BASE_URL = padmaConfig.data_url; var padmaVideo = function(videoId) { this.id = videoId; - 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; +// 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; this.hasAllData = false; this.video = {}; this.layers = {}; @@ -27,6 +27,25 @@ var padmaVideo = function(videoId) { padmaVideo.prototype.getAllData = function(callback, data) { var that = this; if (!this.hasAllData) { + 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; + that.layers = flattenLayers(v.layers); + that.hasAllData = true; + that.hasLayersData = true; + that.videoSrc = that.getVideo(0, '240'); + + callback(that, data); + }, "json"); + +/* $.getScript(that.videoUrl, function() { that.video = video; that.hasVideoData = true; @@ -37,6 +56,7 @@ padmaVideo.prototype.getAllData = function(callback, data) { callback(that, data); }); }); +*/ } else { callback(that, data); } @@ -44,23 +64,26 @@ padmaVideo.prototype.getAllData = function(callback, data) { //tc in npt padmaVideo.prototype.getFrame = function(tc) { - return BASE_URL + this.id + "/frame/" + tc + ".jpg"; + tc = npt2ms(tc) / 1000 + return BASE_URL + this.id + "/240p" + tc + ".jpg"; } //tc in npt padmaVideo.prototype.getVideo = function(tc, size) { - if (!this.hasVideoData) { + if (!this.hasAllData) { return false; } if (typeof(size) == 'undefined') { - size = '128'; + size = '240'; } - return this.video.urls[size] + "?t=npt:" + tc; + return BASE_URL + this.id + "/" + size + "p.webm"; +// return this.video.urls[size] + "?t=npt:" + tc; } padmaVideo.prototype.getDownloadLink = function(tcIn, tcOut) { - return BASE_URL + this.id + "/download/" + tcIn + "-" + tcOut + ".ogv"; + return this.getVideo(0, "480"); +// return BASE_URL + this.id + "/download/" + tcIn + "-" + tcOut + ".ogv"; } @@ -123,6 +146,8 @@ padmaVideo.prototype.getLayersAtTimecode = function(tc) { var layers = []; for (var i=0; i < that.layers.length; i++) { var thisLayer = that.layers[i]; +// thisLayer.time_in = thisLayer.in * 1000; +// thisLayer.time_out = thisLayer.out * 1000; if (tc > thisLayer.time_in && tc < thisLayer.time_out) { layers.push(thisLayer); } @@ -142,6 +167,26 @@ padmaVideo.prototype.getLayerById = function(id) { return false; } +//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