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)',
'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<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) {
var matchedLayers = []
for (var i=0; i < layers.length; i++) {

View File

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

View File

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