diff --git a/css/styles.css b/css/styles.css index 1ef2976..083d6a8 100644 --- a/css/styles.css +++ b/css/styles.css @@ -5,10 +5,6 @@ text-align: center; } -#additionalFeatures { - display: none; -} - #wrapper { margin-top: 30px; width: 100%; diff --git a/index.html b/index.html index 822f5e9..dbc48f5 100644 --- a/index.html +++ b/index.html @@ -123,13 +123,6 @@ A transcribing and subtitling tool for Firefox. It is used for transcribing vide


-
-
- Time to add:
- Start no:
- -
-
diff --git a/js/app.js b/js/app.js index a4948d1..23ffe3c 100644 --- a/js/app.js +++ b/js/app.js @@ -144,102 +144,103 @@ Ox.load({ .css({'position': 'fixed', 'top': '0px', 'left': '0px', 'right': '0px', 'height': '20px'}) .appendTo(Ox.$body) .bindEvent({ - click: function(data) { - if (data.id == 'load_video') { - saveTxt(); - videoPath = undefined; - videoHash = undefined; - textArea.elem.val(''); - var path = data.files[0].name; - if ($.inArray(getFileNameExt(path.toLowerCase()), [ - 'oga', 'ogg', 'ogv', 'ogx', 'wav', 'webm', 'mp4', 'm4v' - ]) != -1) { - loadVideo(data.files[0]); - } else { - alert('You can only open videos in formats supported by the browser.'); - } - } else if(data.id == 'about') { - var html = Ox.tmpl("dialog_about", {}); - stDialog("About", html); - } else if(data.id == 'preferences') { - var prefs = globalUser.get_prefs(["fontSize", "theme", "autosave"]); - var html = Ox.tmpl("dialog_preferences", {}); - stDialog("Preferences", html); - $('.pref_select').each(function() { - var that = this; - var pref = $(this).attr("data-pref"); - var prefVal = prefs[pref]; - $(this).children('option').each(function() { - if ($(this).val() == prefVal) { - $(this).attr("selected", "selected"); - } - }); - }); - $('.pref_select').change(function() { - var key = $(this).attr("data-pref"); - var val = $(this).val(); - globalUser.set_pref(key, val); - }); - /* - $('#pref_fontSize > option').each(function() { - if ($(this).val() == prefs.fontSize) { - $(this).attr("selected", "selected"); - } - }); - $('#pref_theme > option').each(function() { - if ($(this).val() == prefs.theme) { - $(this).attr("selected", "selected"); - } - }); - */ - } else if(data.id == 'shortcuts') { - var html = Ox.tmpl("dialog_shortcuts", {}); - stDialog("Keyboard Shortcuts", html); - } else if(data.id == 'save_srt') { - var content = textArea.toSrt(); - saveContent(content, 'text/plain', getFileNameSansExt(videoPath) + '.srt'); - } else if(data.id == 'load_srt') { - loadSrt(data.files[0]); - } else if(data.id == 'export_encore') { - var content = textArea.toSrt("enc"); - saveContent(content, 'text/plain', getFileNameSansExt(videoPath) + '.enc.txt'); - } else if(data.id == 'export_html') { - var content = textArea.toHTML(); - saveContent(content, 'text/html', getFileNameSansExt(videoPath) + '.html'); - } else if(data.id == 'load_cuts') { - var html = Ox.tmpl("dialog_load_cuts"); - var loadDialog = Ox.Dialog({ - buttons: [ - Ox.Button({ - title: "Cancel" - }).bindEvent({ - click: function() { - loadDialog.close() - } - }), - Ox.Button({ - title: "Load Cuts" - }).bindEvent({ - click: function() { - var url = loadDialog.find('input')[0].value.trim(); - var match = url.match(/(.*)\/([A-Z]+)$/); - if (match) { - loadCuts(match[1] + '/api/', match[2]); - } - loadDialog.close(); - } - }), - ], - content: Ox.Element().append(html) - }).open(); + click: function(data) { + if (data.id == 'load_video') { + saveTxt(); + videoPath = undefined; + videoHash = undefined; + textArea.elem.val(''); + var path = data.files[0].name; + var extension = Ox.last(path.toLowerCase().split('.')); + if (Ox.contains([ + 'oga', 'ogg', 'ogv', 'ogx', 'wav', 'webm', 'mp4', 'm4v' + ], extension)) { + loadVideo(data.files[0]); + } else { + alert('You can only open videos in formats supported by the browser.'); + } + } else if(data.id == 'about') { + var html = Ox.tmpl("dialog_about", {}); + stDialog("About", html); + } else if(data.id == 'preferences') { + var prefs = globalUser.get_prefs(["fontSize", "theme", "autosave"]); + var html = Ox.tmpl("dialog_preferences", {}); + stDialog("Preferences", html); + $('.pref_select').each(function() { + var that = this; + var pref = $(this).attr("data-pref"); + var prefVal = prefs[pref]; + $(this).children('option').each(function() { + if ($(this).val() == prefVal) { + $(this).attr("selected", "selected"); + } + }); + }); + $('.pref_select').change(function() { + var key = $(this).attr("data-pref"); + var val = $(this).val(); + globalUser.set_pref(key, val); + }); + /* + $('#pref_fontSize > option').each(function() { + if ($(this).val() == prefs.fontSize) { + $(this).attr("selected", "selected"); } + }); + $('#pref_theme > option').each(function() { + if ($(this).val() == prefs.theme) { + $(this).attr("selected", "selected"); + } + }); + */ + } else if(data.id == 'shortcuts') { + var html = Ox.tmpl("dialog_shortcuts", {}); + stDialog("Keyboard Shortcuts", html); + } else if(data.id == 'save_srt') { + var content = textArea.toSrt(); + saveContent(content, 'text/plain', getFileNameSansExt(videoPath) + '.srt'); + } else if(data.id == 'load_srt') { + loadSrt(data.files[0]); + } else if(data.id == 'export_encore') { + var content = textArea.toSrt("enc"); + saveContent(content, 'text/plain', getFileNameSansExt(videoPath) + '.enc.txt'); + } else if(data.id == 'export_html') { + var content = textArea.toHTML(); + saveContent(content, 'text/html', getFileNameSansExt(videoPath) + '.html'); + } else if(data.id == 'load_cuts') { + var html = Ox.tmpl("dialog_load_cuts"); + var loadDialog = Ox.Dialog({ + buttons: [ + Ox.Button({ + title: "Cancel" + }).bindEvent({ + click: function() { + loadDialog.close() + } + }), + Ox.Button({ + title: "Load Cuts" + }).bindEvent({ + click: function() { + var url = loadDialog.find('input')[0].value.trim(); + var match = url.match(/(.*)\/([A-Z]+)$/); + if (match) { + loadCuts(match[1] + '/api/', match[2]); + } + loadDialog.close(); + } + }), + ], + content: Ox.Element().append(html) + }).open(); } + } }); textArea = new TextArea("txt"); textArea.elem.val(''); globalUser.init(); - //autosave every 1 minute. + //autosave every 1 minute. window.autosaveInterval = setInterval(function() { if (!Ox.isUndefined(videoHash)) { saveTxt(); @@ -255,7 +256,6 @@ function loadTxt() { } function saveTxt() { - var content = textArea.toSrt(); var txt = textArea.elem.val(); //console.log('saveTxt', videoHash, txt.length); globalUser.set_txt(videoHash, txt); diff --git a/js/classes.js b/js/classes.js index a95c5cb..088280a 100644 --- a/js/classes.js +++ b/js/classes.js @@ -1,6 +1,3 @@ -var url = "https://speedtrans.pad.ma"; - - //elem = string (elementId to make TextArea) var TextArea = function(elem) { this.elem = $('#' + elem); @@ -39,7 +36,7 @@ TextArea.prototype.isTc = function() { var pos = eDom.selectionStart; var word = this.getWord(pos); if (isValidTimecode(word)) { - return npt2ms(word); + return Ox.parseDuration(word); } else { return false; } @@ -54,7 +51,7 @@ TextArea.prototype.insertTc = function(tcNpt) { var val = this.elem.val(); var pos = eDom.selectionStart; if(!tcNpt) { - tcNpt = ms2npt(Video.get()); + tcNpt = Ox.formatDuration(Video.get(), 3); } var newVal = val.substring(0,pos) + "\n" + tcNpt + "\n" + val.substring(pos, val.length); e.val(newVal); @@ -103,52 +100,29 @@ function cleanNewlines(str) { TextArea.prototype.fromSrt = function(txt) { var that = this; this.spans = []; - var cleaned = cleanNewlines(txt); - var srt = strip(cleaned); - var srt_ = srt.split('\n\n'); - var s; - for(s in srt_) { - st = srt_[s].split('\n'); - if(st.length >=2) { - var n = st[0]; - var i = strip(st[1].split(' --> ')[0]); - var o = strip(st[1].split(' --> ')[1]); - var t = st[2]; - if(st.length > 2) { - for(j=3; j " + "0" + ms2npt(s.tcOutMs).replace(".", ","); - srt += "\n"; - srt += text; - srt += "\n\n"; - } - else if (fmt == 'enc') { - srt += srtNo + " " + ms2frames(s.tcInMs) + " " + ms2frames(s.tcOutMs) + " " + text; - srt += "\n\n"; - } - srtNo++; } + 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; } @@ -241,24 +209,7 @@ TextArea.prototype.toSrt = function(fmt) { this.spans = spans; var srt = spansToSrt(spans, fmt); //console.log(srt); - return Ox.encodeUTF8(srt); -} - - -TextArea.prototype.addTime = function(ms, start_no) { -//console.log(ms); - this.toSrt(); - var s = []; - var spans = this.spans; - for (var i=0; i < spans.length;i++) { - s[i] = { - index: i, - tcOutMs: spans[i].tcOutMs + ms, - text: spans[i].text, - tcInMs: spans[i].tcInMs + ms - } - } - return spansToSrt(s, 'srt', start_no); + return srt; } @@ -270,7 +221,7 @@ TextArea.prototype.toHTML = function() { span = spans[i]; txt = ''; txt += '

\n'; - txt += ''; + txt += ''; txt += (i + 1).toString(); txt += "\n"; txt += '
\n'; @@ -285,9 +236,9 @@ TextArea.prototype.toHTML = function() { //creates new Span (tcIn and tcOut in npt format) var Span = function(tcIn, tcOut, text, index) { this.index = index; - this.tcOutMs = npt2ms(tcOut); + this.tcOutMs = Ox.isString(tcOut) ? Ox.parseDuration(tcOut) : tcOut; this.text = text; - this.tcInMs = npt2ms(tcIn); + this.tcInMs = Ox.isString(tcOut) ? Ox.parseDuration(tcIn) : tcIn; } var SeekBar = function(elem) { @@ -307,7 +258,7 @@ SeekBar.prototype.init = function() { drag: function() { clearInterval(videoListener); var pos = that.get(); - $('#timeCode').html(ms2npt(pos)); + $('#timeCode').html(Ox.formatDuration(pos, 3)); }, stop: function() { var pos = that.get(); @@ -432,7 +383,7 @@ function loadCuts(url, id) { pandora_api('get', {id: id, keys: ['cuts']}, function(result) { var txt = ''; result.data.cuts.forEach(function(cut) { - textArea.insertTc(ms2npt(cut)); + textArea.insertTc(Ox.formatDuration(cut)); }); }); } diff --git a/js/player.js b/js/player.js index 330b40c..959c233 100644 --- a/js/player.js +++ b/js/player.js @@ -121,12 +121,12 @@ VideoPlayer.prototype.togglePause = function() { VideoPlayer.prototype.listener = function() { var t = Video.get(); - var npt = ms2npt(t); + var npt = Ox.formatDuration(t, 3); $('#timeCode').html(npt); var seekBarPos = parseInt((t/Video.duration) * 320); $('#seekPointer').css("left", seekBarPos + "px"); - } +} VideoPlayer.prototype.setDuration = function(duration) { this.duration = duration; - } +} diff --git a/js/staticfuncs.js b/js/staticfuncs.js index 2e3ac7d..70c36dd 100644 --- a/js/staticfuncs.js +++ b/js/staticfuncs.js @@ -1,88 +1,27 @@ -function npt2ms(npt) { - var ms = 0.0 - npt = String(npt); - var p = npt.split(':') - for(i=0;i 3) { - ms = ms.toString().substring(0,3); - } - ss = it % 60; - mm = ((it - ss) / 60) % 60; - hh = ((it - (mm * 60) - ss) / 3600) % 60; - npt = hh+':'+strpad(mm.toString(), '0', 2, 'left') - npt += ':'+strpad(ss.toString(), '0', 2, 'left') - npt += '.'+strpad(ms.toString(), '0', 3, 'left') - return npt; -} - -function ms2frames(ms, fmt) { - if (!fmt) var fmt = "PAL"; - var npt = ms2npt(ms); +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); - if (fmt == 'PAL') { - var frames = parseInt((mmInt / 1000) * 24); - } else if (fmt == "NTSC") { - var frames = parseInt((mmInt / 1000) * 29.97); - } + var frames = parseInt((mmInt / 1000) * 24); var framesTc = ''; var joinToken = ":"; var framesTc = npt.substring(0, dotpos ) + joinToken + frames; return framesTc; -} - -function ms2time(ms) { - var npt = ms2npt(ms) - return npt.substr(npt.length-9, npt.length-6); -} - - -function strpad(str, pad, len, dir) { - while (str.length < len) { - if (dir == 'left') - str = pad + str; - else if (dir == 'right') - str = str + pad; - } - return str; } 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);to -} - -//where filters is a JSON object, for eg. {'Video Files': '*.dv;*.ogg;*.ogv;*.ogx;*.avi;*.mov;*.mp4;*.mpeg;*.mpg;*.vob'} -function selectFile(filters, callback) { - alert('select file'); - //fixme. select file - callback && callback(fp); -} - -function getFileNameExt(filename) { - var dotPos = filename.lastIndexOf("."); - var ext = filename.substring(dotPos + 1, filename.length); - return ext; + return nptRegex.test(tc); } function getFileNameSansExt(filename) { var dotPos = filename.lastIndexOf("."); if (dotPos != '-1') { - var filenameSansExt = filename.substring(0,dotPos); - } else { + var filenameSansExt = filename.substring(0, dotPos); + } else { var filenameSansExt = filename; - } + } return filenameSansExt; }