242 lines
7.4 KiB
JavaScript
242 lines
7.4 KiB
JavaScript
//init globals
|
|
//var seekBar;
|
|
var textArea;
|
|
var Video;
|
|
var filePath = false;
|
|
var videoListener;
|
|
|
|
$(document).ready(function() {
|
|
var loadingIcon = new Ox.LoadingIcon({
|
|
size: "medium"
|
|
})
|
|
.css({
|
|
marginLeft: "4px"
|
|
});
|
|
var mainMenu = new Ox.MainMenu({
|
|
extras: [],
|
|
menus: [
|
|
{
|
|
id: "speedtrans",
|
|
title: "Pad.ma",
|
|
items: [
|
|
{ id: "about", title: "About" },
|
|
{},
|
|
{ id: "contact", title: "Contact"}
|
|
]
|
|
},
|
|
{
|
|
id: "video",
|
|
title: "Video",
|
|
items: [
|
|
{ id: "loadvideo", title: "Load Ogg Video"},
|
|
{},
|
|
{ id: "convertvideo", title: "Convert and load Video" }
|
|
]
|
|
},
|
|
{
|
|
id: "srt",
|
|
title: "Subtitles",
|
|
items: [
|
|
{ id: "load", title: "Open" },
|
|
{ id: "save", title: "Save" },
|
|
{ id: "save_as", title: "Save As..."}
|
|
]
|
|
},
|
|
{
|
|
id: "export",
|
|
title: "Export",
|
|
items: [
|
|
{ id: "export_srt", title: "Export Srt" },
|
|
{ id: "export_encore", title: "Export Adobe Encore Subtitle Format" },
|
|
{},
|
|
{ id: "add_time", title: "Add / Subtract time and export" }
|
|
]
|
|
},
|
|
{
|
|
id: "help",
|
|
title: "Help",
|
|
items: [
|
|
{ id: "help", title: "Help" }
|
|
]
|
|
}
|
|
],
|
|
size: "large"
|
|
});
|
|
mainMenu.css({'position': 'absolute', 'top': '0px', 'left': '0px', 'width': '90%'}).appendTo('body');
|
|
Ox.Event.bind(null, "click_loadvideo", function() {
|
|
var videoFile = selectFile();
|
|
filePath = getFileNameSansExt(videoFile);
|
|
var srtTxtFilename = filePath + ".srt.txt";
|
|
var srtFilename = filePath + ".srt";
|
|
var metaFilename = filePath + ".txt";
|
|
if (checkFileExists(srtTxtFilename)) {
|
|
loadSrtTxt(srtTxtFilename);
|
|
} else if (checkFileExists(srtFilename)) {
|
|
loadSrt(srtFilename);
|
|
}
|
|
if (checkFileExists(metaFilename)) {
|
|
loadMeta(metaFilename);
|
|
}
|
|
$('#video').attr("src", "file://" + videoFile);
|
|
document.getElementById("video").load();
|
|
$('#video').one("loadedmetadata", function() {
|
|
// $('#selectFileDiv').fadeOut();
|
|
Video = new VideoPlayer();
|
|
Video.init("video");
|
|
//
|
|
// seekBar = new SeekBar("seekBar");
|
|
Video.setDuration(Video.player.duration);
|
|
$('#insertTc').click(textArea.insertTc);
|
|
/* $('#video').click(function() {
|
|
Video.togglePause();
|
|
});
|
|
*/
|
|
$('#video').dblclick(function() {
|
|
textArea.insertTc();
|
|
});
|
|
videoListener = setInterval(Video.listener, 250);
|
|
});
|
|
});
|
|
|
|
Ox.Event.bind(null, "click_about", function() {
|
|
stDialog("About", "This is about us");
|
|
});
|
|
Ox.Event.bind(null, "click_help", function() {
|
|
var html = "Shortcuts: <br /><br /> \
|
|
Esc: Pause / Unpause <br /> \
|
|
Insert: Insert time-code<br /> \
|
|
PageUp / PageDown: Volume Up / Down<br /> \
|
|
Double-click in Textarea: insert time-code <br /> \
|
|
Double-click on video: insert time-code<br /> \
|
|
Double-click on time-code in textarea: Seek video to time-code. <br />"
|
|
stDialog("Help", html);
|
|
});
|
|
textArea = new TextArea("txt");
|
|
$('#saveFile').click(saveFile);
|
|
$('#saveSrt').click(saveSrt);
|
|
$('#addTime').click(function() {
|
|
var timeToAdd = npt2ms($.trim($('#timeToAdd').val()));
|
|
var startNo = parseInt($('#startNo').val());
|
|
var r = textArea.addTime(timeToAdd, startNo);
|
|
$('#addTimeResult').val(r);
|
|
});
|
|
$('#showMore').toggle(function() {
|
|
$(this).text("Show Less Features");
|
|
$('#additionalFeatures').show("fast");
|
|
}, function() {
|
|
$(this).text("Show More Features");
|
|
$('#additionalFeatures').hide("fast");
|
|
});
|
|
$('#saveEncore').click(saveEncore);
|
|
$('#selectFile').click(function() {
|
|
|
|
});
|
|
|
|
$(document).keyup(function(e) {
|
|
//Esc
|
|
if (e.keyCode == 27 && textArea.hasFocus) {
|
|
Video.togglePause();
|
|
}
|
|
//Ins
|
|
if (e.keyCode == 45) {
|
|
if (!textArea.isTc()) {
|
|
textArea.insertTc();
|
|
}
|
|
}
|
|
//Ctrl - Seek Back
|
|
if (e.keyCode == 17) {
|
|
var seekTime = parseInt(parseFloat($('#seekTime').val()) * 1000);
|
|
var currTime = Video.get();
|
|
var newTime = currTime - seekTime;
|
|
Video.set(newTime);
|
|
}
|
|
//Alt - Seek Fwd.
|
|
if (e.keyCode == 18) {
|
|
var seekTime = parseInt(parseFloat($('#seekTime').val()) * 1000);
|
|
var currTime = Video.get();
|
|
var newTime = currTime + seekTime;
|
|
Video.set(newTime);
|
|
}
|
|
|
|
//Space - togglePause if no focus on TA
|
|
if (e.keyCode == 32 && textArea.hasFocus == false) {
|
|
Video.togglePause();
|
|
}
|
|
|
|
//PageUp - volume Up:
|
|
if (e.keyCode == 33) {
|
|
Video.volUp();
|
|
return false;
|
|
}
|
|
|
|
if (e.keyCode == 34) {
|
|
Video.volDown();
|
|
return false;
|
|
}
|
|
});
|
|
|
|
$('#fillMeta').click(function() {
|
|
$('#txtWrapper').hide();
|
|
$('#eventMetadata').show();
|
|
});
|
|
$('#doneMetadata').click(function() {
|
|
$('#eventMetadata').hide();
|
|
$('#txtWrapper').show();
|
|
});
|
|
$('.eventMeta').each(function() {
|
|
var defVal = $(this).attr('data-default');
|
|
$(this).val(defVal);
|
|
$(this).focus(function() {
|
|
if ($(this).val() == $(this).attr("data-default")) {
|
|
$(this).val('');
|
|
}
|
|
}).blur(function() {
|
|
if ($(this).val() == '') {
|
|
$(this).val($(this).attr('data-default'));
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
function saveFile() {
|
|
var savePath = filePath + ".srt.txt";
|
|
var content = $('#txt').val();
|
|
if (mozillaSaveFile(savePath, content)) {
|
|
alert("saved file at " + savePath);
|
|
} else {
|
|
alert("error saving file");
|
|
}
|
|
}
|
|
|
|
function saveSrt() {
|
|
var srtPath = filePath + ".srt";
|
|
var content = textArea.toSrt();
|
|
if (mozillaSaveFile(srtPath, content)) {
|
|
alert("export .srt file to " + srtPath);
|
|
} else {
|
|
alert("error exporting srt");
|
|
}
|
|
}
|
|
|
|
function saveEncore() {
|
|
var encPath = filePath + ".enc.txt";
|
|
var content = textArea.toSrt("enc");
|
|
if (mozillaSaveFile(encPath, content)) {
|
|
alert("saved encore compatible subtitle file at " + encPath);
|
|
} else {
|
|
alert("error creating encore compatible subtitle file");
|
|
}
|
|
}
|
|
|
|
function stDialog(titleTxt, text) {
|
|
var dialog = new Ox.Dialog({
|
|
buttons:
|
|
[
|
|
{ value: "Close", click: function() { dialog.close(); } }
|
|
],
|
|
title: titleTxt
|
|
}).append(text);
|
|
dialog.open();
|
|
return dialog;
|
|
}
|