$(document).ready(function() { $('#fetchVideoData').click(function() { var padmaId = $('#padmaId').val(); var srtUrl = "/fetchSrt?id=" + padmaId + "&track=transcripts"; // console.log(srtUrl); var videoJs = PADMA_BASE_URL + "/" + padmaId + "/video.js"; $.getScript(videoJs, function() { // console.log(video); var thisVideo = video; var videoSrc = video.urls['320']; $('#video').attr("src", videoSrc); document.getElementById("video").load(); //FIXME // $('#srt').html(rawSrt); $('#srt').srt({ 'url': srtUrl, 'id': 'video', 'showSubtitle': function(sub, elem) { var html = sub.i + " - " + sub.o; html += "
"; html += sub.t; elem.html(html); }, 'subtitlesLoaded': function(subtitles) { // console.log(subtitles); var str = ''; var counter = 1; for (var s in subtitles) { if (subtitles.hasOwnProperty(s)) { var thisSubtitle = subtitles[s]; var inTime = thisSubtitle.i; var outTime = thisSubtitle.o; str += "" + counter + "\n" + inTime + " --> " + outTime + "\n\n" counter++; // str += inTime + "\n\n" + outTime + "\n\n"; } } $('#newSrt').val(str); } }); }); }); $('#saveSrt').click(function() { var txt = $('#newSrt').val(); var language = $('#language').val(); $.post("saveSrt", { 'txt': txt, 'language': language, 'padmaId': $('#padmaId').val() }, function(response) { alert(response); }); }); $('#loadSrt').click(function() { $.get("loadSrt", { 'padmaId': $('#padmaId').val(), 'language': $('#languageLoad').val() }, function(srt) { $('#newSrt').val(srt); }); }); }); function s2npt(s) { return ms2npt(s * 1000); } function ms2npt(pos) { var h = Math.floor(pos / 3600000); var m = Math.floor(pos % 3600000 / 60000); var s = Math.floor(pos % 60000 / 1000); var ms = pos % 1000; return h.toString().pad('0', 2) + ':' + m.toString().pad('0', 2) + ':' + s.toString().pad('0', 2) + '.' + ms.toString().pad('0', 3); // return strpad(h.toString(), '0', 2, 'left') + ':' + strpad(m.toString(), '0', 2, 'left') + ':' + strpad(s.toString(), '0', 2, 'left') + '.' + strpad(ms.toString(), '0', 3, 'left'); } String.prototype.pad = function(pad, len, dir) { if (typeof(dir) == 'undefined') dir = 'left'; var str = this; while (str.length < len) { if (dir == 'left') str = pad + str; else if (dir == 'right') str = str + pad; } return str; }