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) { pandora.ui.videoPlayer = function(options) {
var url = options.url; var url = options.url;
var timeline = options.timeline || "foo.png"; //FIXME var timeline = options.timeline || "foo.png"; //FIXME

View File

@ -37,7 +37,7 @@
}); });
} }
var prefix = "js/"; 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 prefix = "js/ui/";
var filesToLoad = Ox.map(files, function(v) { var filesToLoad = Ox.map(files, function(v) {
return prefix + v + ".js"; return prefix + v + ".js";
@ -53,6 +53,8 @@
function initSpeedtrans(data) { function initSpeedtrans(data) {
pandora.$ui.appPanel = pandora.ui.appPanel().appendTo(pandora.$ui.body); pandora.$ui.appPanel = pandora.ui.appPanel().appendTo(pandora.$ui.body);
pandora.$ui.openRemoteDialog = pandora.ui.openRemoteDialog();
pandora.$ui.openSRTDialog = pandora.ui.openSRTDialog();
pandora.resizeWindow(); pandora.resizeWindow();
} }

View File

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

View File

@ -16,13 +16,42 @@ pandora.ui.openRemoteDialog = function() {
// }); // });
//FIXME: convert to SelectInput //FIXME: convert to SelectInput
var $input1 = Ox.Input({
'label': 'Pan.do/ra instance URL', var instances = [
'id': 'pandoraInstance', {
'labelWidth': 250, 'id': 'http://pad.ma',
'width': 600 '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'}); }).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({ var $input2 = Ox.Input({
'label': 'Pan.do/ra Video ID', 'label': 'Pan.do/ra Video ID',
'id': 'pandoraID', '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 = { that.speedtrans = {
spans: [], spans: [],
storage: '',
insertTc: function() { insertTc: function() {
var eDom = that.find("textarea").get(0); //FIXME var eDom = that.find("textarea").get(0); //FIXME
var scrollTop = eDom.scrollTop; var scrollTop = eDom.scrollTop;
@ -102,13 +103,47 @@ pandora.ui.textArea = function() {
// console.log(srt); // console.log(srt);
return srt; return srt;
}, },
fromSrt: function(txt) {
save: function() { 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()); console.log(that.value());
var filename = pandora.$ui.videoPlayer.options("video"); //var videoName = pandora.$ui.videoPlayer.videoName;
console.log(filename); //console.log(videoName);
pandora.storage(filename, {'text': that.value()}); console.log(that.storage);
pandora.storage(that.storage, {'text': that.value()});
}, },
load: function(options) { load: function(options) {
console.log(options); console.log(options);
@ -121,6 +156,7 @@ pandora.ui.textArea = function() {
// var name = options.name; // var name = options.name;
// } // }
var val = pandora.storage(options.name) || {'text': ''}; var val = pandora.storage(options.name) || {'text': ''};
that.storage = options.name;
that.value(val.text); that.value(val.text);
var videoOptions = { var videoOptions = {
'url': options.url 'url': options.url

View File

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