moving to next.pad.ma

This commit is contained in:
Sanj 2012-02-15 15:05:45 +05:30
parent d712740014
commit d94b749eac
3 changed files with 75 additions and 28 deletions

View File

@ -2,8 +2,8 @@ var padmaConfig = {
'background': 'rgba(0,0,0,0.85)', 'background': 'rgba(0,0,0,0.85)',
'color': '#fff', 'color': '#fff',
'links_url': 'pad.ma/', 'links_url': 'pad.ma/',
'data_url': 'http://pad.ma/', 'data_url': 'http://next.pad.ma/',
'default_layers': ['transcript', 'description'], 'default_layers': ['transcripts', 'descriptions'],
}; };
(function($) { (function($) {
@ -12,11 +12,11 @@ var BASE_URL = padmaConfig.data_url;
var padmaVideo = function(videoId) { var padmaVideo = function(videoId) {
this.id = videoId; this.id = videoId;
this.videoUrl = BASE_URL + videoId + "/video.js"; // this.videoUrl = BASE_URL + videoId + "/video.js";
this.layersUrl = BASE_URL + videoId + "/layers.js"; // this.layersUrl = BASE_URL + videoId + "/layers.js";
this.infoUrl = BASE_URL + videoId + "/info"; // this.infoUrl = BASE_URL + videoId + "/info";
this.hasVideoData = false; // this.hasVideoData = false;
this.hasLayersData = false; // this.hasLayersData = false;
this.hasAllData = false; this.hasAllData = false;
this.video = {}; this.video = {};
this.layers = {}; this.layers = {};
@ -27,6 +27,25 @@ var padmaVideo = function(videoId) {
padmaVideo.prototype.getAllData = function(callback, data) { padmaVideo.prototype.getAllData = function(callback, data) {
var that = this; var that = this;
if (!this.hasAllData) { 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() { $.getScript(that.videoUrl, function() {
that.video = video; that.video = video;
that.hasVideoData = true; that.hasVideoData = true;
@ -37,6 +56,7 @@ padmaVideo.prototype.getAllData = function(callback, data) {
callback(that, data); callback(that, data);
}); });
}); });
*/
} else { } else {
callback(that, data); callback(that, data);
} }
@ -44,23 +64,26 @@ padmaVideo.prototype.getAllData = function(callback, data) {
//tc in npt //tc in npt
padmaVideo.prototype.getFrame = function(tc) { 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 //tc in npt
padmaVideo.prototype.getVideo = function(tc, size) { padmaVideo.prototype.getVideo = function(tc, size) {
if (!this.hasVideoData) { if (!this.hasAllData) {
return false; return false;
} }
if (typeof(size) == 'undefined') { 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) { 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 = []; var layers = [];
for (var i=0; i < that.layers.length; i++) { for (var i=0; i < that.layers.length; i++) {
var thisLayer = that.layers[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) { if (tc > thisLayer.time_in && tc < thisLayer.time_out) {
layers.push(thisLayer); layers.push(thisLayer);
} }
@ -142,6 +167,26 @@ padmaVideo.prototype.getLayerById = function(id) {
return false; 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<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;
}
function filterLayersByTracks(layers, tracks) { function filterLayersByTracks(layers, tracks) {
var matchedLayers = [] var matchedLayers = []
for (var i=0; i < layers.length; i++) { for (var i=0; i < layers.length; i++) {

View File

@ -16,12 +16,14 @@
var link = href; var link = href;
if (link.indexOf(PADMA_URL) != -1) { if (link.indexOf(PADMA_URL) != -1) {
var linkData = parsePadmaUrl(link, PADMA_URL); var linkData = parsePadmaUrl(link, PADMA_URL);
if (linkData && $.inArray(linkData.type, ['info', 'tcRange', 'editor', 'tc', 'layer'])) { console.log(linkData.type);
//Don't fetch data twice if video id already exists // if (linkData && $.inArray(linkData.type, ['info', 'tcRange', 'editor', 'tc', 'layer'])) {
if (linkData && $.inArray(linkData.type, ['tcRange', 'info']) != -1) {
$(that).addClass('padmaLink'); $(that).addClass('padmaLink');
var videoId = linkData.videoId; var videoId = linkData.videoId;
// console.log(linkData);
/* /*
var cacheVideo = padmaVideo.getFromCache(videoId); var cacheVideo = padmaVideo.getFromCache(videoId);
if (cacheVideo) { if (cacheVideo) {

View File

@ -92,22 +92,22 @@ Gives a bunch of data parsed from a pad.ma url
*/ */
function parsePadmaUrl(link, padma_url) { function parsePadmaUrl(link, padma_url) {
// console.log(padma_url);
var regex = new RegExp("http://.*" + padma_url); var regex = new RegExp("http://.*" + padma_url);
var linkStr = link.replace(regex, ""); var linkStr = link.replace(regex, "");
// console.log(linkStr); // alert(linkStr);
// console.log(linkStr); // console.log("linkStr", linkStr);
var r = { }; var r = { };
r.url = link; r.url = link;
// console.log(link); // console.log(link);
if (linkStr.charAt(0) == 'V') { var idRegex = /([A-Z]*?)\//;
// console.log("Hello"); if (linkStr.match(idRegex)) { // FIXME
var idRegex = /V(.{1,7})/;
var idMatch = linkStr.match(idRegex); var idMatch = linkStr.match(idRegex);
// console.log("match", idMatch); // console.log("match", idMatch);
r.videoId = idMatch[0]; r.videoId = idMatch[1]
// console.log(videoId); // console.log(r.videoId);
var postIdStr = linkStr.replace(idMatch[0] + "/", ''); var postIdStr = linkStr.replace(r.videoId + "/", '');
// console.log("postId", postIdStr);
if (postIdStr == 'info' || postIdStr == '') { if (postIdStr == 'info' || postIdStr == '') {
r.type = 'info'; r.type = 'info';
return r; return r;
@ -118,11 +118,11 @@ Gives a bunch of data parsed from a pad.ma url
r.type = 'layer'; r.type = 'layer';
r.layerId = postIdStr; r.layerId = postIdStr;
return r; return r;
} else if (postIdStr.indexOf("-") != -1) { } else if (postIdStr.indexOf(",") != -1) {
var tcs = postIdStr.split("-"); var tcs = postIdStr.split(",");
r.type = 'tcRange'; r.type = 'tcRange';
r.tcIn = tcs[0]; r.tcIn = tcs[0];
r.tcOut = tcs[1]; r.tcOut = tcs[1].replace("/", "");
return r; return r;
} else { } else {
r.type = 'tc'; r.type = 'tc';