98 lines
2.5 KiB
JavaScript
98 lines
2.5 KiB
JavaScript
function formatFrames(seconds) {
|
|
var npt = Ox.formatDuration(seconds, 3);
|
|
var dotpos = npt.lastIndexOf(".");
|
|
var mmStr = npt.substring(dotpos + 1, npt.length);
|
|
var mmInt = parseInt(mmStr);
|
|
var frames = parseInt((mmInt / 1000) * 24);
|
|
var framesTc = '';
|
|
var joinToken = ":";
|
|
var framesTc = npt.substring(0, dotpos ) + joinToken + frames;
|
|
return framesTc;
|
|
}
|
|
|
|
function isValidTimecode(tc) {
|
|
var tc = $.trim(tc);
|
|
var nptRegex = new RegExp("^[0-9][0-9]?\:[0-9][0-9]\:[0-9][0-9][\.|\,|\:][0-9]?[0-9]?[0-9]?$");
|
|
return nptRegex.test(tc);
|
|
}
|
|
|
|
function getFileNameSansExt(filename) {
|
|
var dotPos = filename.lastIndexOf(".");
|
|
if (dotPos != '-1') {
|
|
var filenameSansExt = filename.substring(0, dotPos);
|
|
} else {
|
|
var filenameSansExt = filename;
|
|
}
|
|
return filenameSansExt;
|
|
}
|
|
|
|
function cleanNewlines(str) {
|
|
var s = str.replace(/\r\n|\r|\n/g, '\n');
|
|
return s;
|
|
}
|
|
|
|
function formatEnc(data) {
|
|
var r = '', n = 1;
|
|
data.forEach(function(item) {
|
|
r += n + ' ' + formatFrames(item['in']) + ' ' + formatFrames(item.out) + ' ' + item.text;
|
|
r += '\n\n';
|
|
n++;
|
|
});
|
|
return r;
|
|
}
|
|
|
|
function spansToSrt(arr, fmt, start_no) {
|
|
if (typeof start_no == 'undefined') {
|
|
start_no = 1;
|
|
}
|
|
var srt = [];
|
|
arr.forEach(function(s) {
|
|
if (s.text.trim() == '') {
|
|
} else {
|
|
var text = s.text.trim();
|
|
linebreaksRegex = new RegExp('\n+', "g")
|
|
text = text.replace(linebreaksRegex, "\n");
|
|
if (!s.tcOutMs) {
|
|
s.tcOutMs = Video.player.duration;
|
|
}
|
|
srt.push({
|
|
'in': s.tcInMs,
|
|
out: s.tcOutMs,
|
|
text: text
|
|
});
|
|
}
|
|
});
|
|
if (fmt == 'srt') {
|
|
return Ox.formatSRT(srt);
|
|
} else if (fmt == 'enc') {
|
|
return formatEnc(srt);
|
|
}
|
|
return srt;
|
|
}
|
|
|
|
function loadCuts(url, id) {
|
|
function pandora_api(action, data, callback) {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: url,
|
|
data: {action: action, data: JSON.stringify(data)},
|
|
success: callback,
|
|
dataType: 'json'
|
|
});
|
|
}
|
|
pandora_api('get', {id: id, keys: ['cuts']}, function(result) {
|
|
var txt = '';
|
|
result.data.cuts.forEach(function(cut) {
|
|
textArea.insertTc(Ox.formatDuration(cut));
|
|
});
|
|
});
|
|
}
|
|
|
|
function loadSrt(file) {
|
|
var reader = new FileReader();
|
|
reader.onload = function(data) {
|
|
textArea.fromSrt(data.target.result);
|
|
};
|
|
reader.readAsText(file);
|
|
}
|
|
|