basic load SRT from paste

This commit is contained in:
Sanjay B 2013-03-05 17:20:51 +05:30
parent 7743617aac
commit 4336ddc8bf
7 changed files with 114 additions and 18 deletions

View File

@ -120,7 +120,6 @@ pandora.ui.videoPanel = function() {
}
//FIXME: should be ui.videoPlayer
pandora.ui.videoPlayer = function(options) {
var url = options.url;
var timeline = options.timeline || "foo.png"; //FIXME

View File

@ -37,7 +37,7 @@
});
}
var prefix = "js/";
var files = ['appPanel', 'mainMenu', 'mainPanel', 'videoPanel', 'videoPlayer', 'openRemoteDialog', 'helpPanel', 'textPanel', 'textArea', 'textToolBar'];
var files = ['appPanel', 'mainMenu', 'mainPanel', 'videoPanel', 'videoPlayer', 'openRemoteDialog', 'openSRTDialog', 'helpPanel', 'textPanel', 'textArea', 'textToolBar'];
var prefix = "js/ui/";
var filesToLoad = Ox.map(files, function(v) {
return prefix + v + ".js";
@ -53,6 +53,8 @@
function initSpeedtrans(data) {
pandora.$ui.appPanel = pandora.ui.appPanel().appendTo(pandora.$ui.body);
pandora.$ui.openRemoteDialog = pandora.ui.openRemoteDialog();
pandora.$ui.openSRTDialog = pandora.ui.openSRTDialog();
pandora.resizeWindow();
}

View File

@ -21,6 +21,7 @@ pandora.ui.mainMenu = function() {
}
},
{ id: 'openRemoteFileMenu', title: 'Open online pan.do/ra file'},
{ id: 'openSRT', title: 'Load SRT file'},
{ id: 'saveFileMenu', title: 'Save File', keyboard: 'shift control s'}
]
}
@ -50,8 +51,9 @@ pandora.ui.mainMenu = function() {
//console.log(data.files[0]);
} else if (data.id == 'openRemoteFileMenu') {
pandora.$ui.openRemoteDialog = pandora.ui.openRemoteDialog().open();
pandora.$ui.openRemoteDialog.open();
} else if (data.id == 'openSRT') {
pandora.$ui.openSRTDialog.open();
} else if (data.id == 'TestMenu1') {
alert("clicked TestMenu1");
}

View File

@ -16,13 +16,42 @@ pandora.ui.openRemoteDialog = function() {
// });
//FIXME: convert to SelectInput
var $input1 = Ox.Input({
'label': 'Pan.do/ra instance URL',
'id': 'pandoraInstance',
'labelWidth': 250,
'width': 600
var instances = [
{
'id': 'http://pad.ma',
'title': 'Pad.ma'
},
{
'id': 'http://0xdb.org',
'title': 'Oxdb'
},
{
'id': 'http://indiancine.ma',
'title': 'IndianCine.ma'
},
{
'id': 'other',
'title': 'Other...'
}
]
var $input1 = Ox.SelectInput({
'items': instances,
'label': 'Site',
'placeholder': 'http://example.com',
'max': 1,
'min': 1,
'value': instances[0]['id'],
}).css({'margin': '4px'});
// var $input1 = Ox.Input({
// 'label': 'Pan.do/ra instance URL',
// 'id': 'pandoraInstance',
// 'labelWidth': 250,
// 'width': 600
// }).css({'margin': '4px'});
var $input2 = Ox.Input({
'label': 'Pan.do/ra Video ID',
'id': 'pandoraID',

27
js/ui/openSRTDialog.js Normal file
View File

@ -0,0 +1,27 @@
pandora.ui.openSRTDialog = function() {
var $textInput = Ox.Input({
'type': 'textarea',
'label': 'Paste SRT',
'id': 'srtText',
'labelWidth': 150,
'width': 500,
'height': 400
});
var $content = Ox.Element().append($textInput);
var that = Ox.Dialog({
'content': $content,
'closeButton': true,
'buttons': [
Ox.Button({
'group': true,
'id': 'loadSRTButton',
'title': 'Load SRT'
}).bindEvent("click", function() {
var txt = $textInput.value();
pandora.$ui.textArea.speedtrans.fromSrt(txt);
that.close();
})
]
});
return that;
};

View File

@ -9,6 +9,7 @@ pandora.ui.textArea = function() {
that.speedtrans = {
spans: [],
storage: '',
insertTc: function() {
var eDom = that.find("textarea").get(0); //FIXME
var scrollTop = eDom.scrollTop;
@ -102,13 +103,47 @@ pandora.ui.textArea = function() {
// console.log(srt);
return srt;
},
fromSrt: function(txt) {
var annots = Ox.parseSRT(txt);
var i = 0;
var spans = Ox.map(annots, function(v) {
var obj = {
'tcInMs': parseInt(v['in'] * 1000),
'tcOutMs': parseInt(v.out * 1000),
'text': v.text,
'index': i
}
i++;
return obj;
});
console.log(spans);
var out = '';
for (span in spans) {
if (spans.hasOwnProperty(span)) {
var sp = spans[span];
out += ms2npt(sp.tcInMs) + "\n";
out += sp.text;
out += "\n";
//If the outpoint of current span is equal to inpoint of next span, dont print out timecode, and just add the extra \n to go to next span.
if (span < spans.length - 1) {
var p = parseInt(span) + 1;
if (spans[p].tcInMs != sp.tcOutMs) {
out += ms2npt(sp.tcOutMs) + "\n\n";
} else {
out += "\n";
}
}
}
}
console.log(out);
that.value(out);
},
save: function() {
console.log(that.value());
var filename = pandora.$ui.videoPlayer.options("video");
console.log(filename);
pandora.storage(filename, {'text': that.value()});
//var videoName = pandora.$ui.videoPlayer.videoName;
//console.log(videoName);
console.log(that.storage);
pandora.storage(that.storage, {'text': that.value()});
},
load: function(options) {
console.log(options);
@ -121,6 +156,7 @@ pandora.ui.textArea = function() {
// var name = options.name;
// }
var val = pandora.storage(options.name) || {'text': ''};
that.storage = options.name;
that.value(val.text);
var videoOptions = {
'url': options.url

View File

@ -1,15 +1,15 @@
pandora.ui.videoPlayer = function(options) {
var url = options.url;
// var url = options.url;
var timeline = options.timeline || "foo.png"; //FIXME
var that = pandora.$ui.videoPlayer = Ox.VideoPlayer({
video: url,
video: options.url,
controlsTop: ['fullscreen'],
controlsBottom: ['play', 'volume', 'scale', 'timeline', 'position'],
height: 300,
width: 400,
showControlsOnLoad: true,
duration: 35,
timeline: timeline,
timeline: options.timeline || 'foo.png',
title: 'Test Video',
enableTimeline: true,
enableKeyboard: true,
@ -17,6 +17,7 @@ pandora.ui.videoPlayer = function(options) {
externalControls: true
// enableTimeline: true
});
//that.videoName = options.name;
return that;
};