$(function() {
$('.title').data("loading", false);
$('.title').click(function() {
var $this = $(this);
if ($(this).data("loading")) {
return;
}
$(this).data("loading", true);
var $parent = $(this).parent();
if ($parent.find('.srtContainer').length > 0) {
$parent.find('.srtContainer').slideToggle();
return;
}
var name = $parent.attr("data-name");
var srtFilename = "srt/" + name + ".srt";
var audioFilename = "wav/" + name + ".wav";
$.get(srtFilename, {}, function(srt) {
$this.data("loading", false);
var txt = srtToTxt(srt, 'tc');
var $txtContainer = $('
').addClass("srtContainer").data("srt", srt).hide()
var $audio = $('').attr("src", audioFilename).attr("controls", "controls").appendTo($txtContainer);
var $btnsContainer = $('').addClass("btnsContainer").appendTo($txtContainer);
var $padmaBtn = $('').addClass("padmaBtn").text("View on pad.ma").appendTo($btnsContainer);
var $srtBtn = $('').addClass("srtBtn").text("View SRT").data("fmt", "srt").appendTo($btnsContainer);
var $tcBtn = $('').addClass("srtBtn").text("View Time-coded Text").data("fmt", "tc").appendTo($btnsContainer);
var $txtBtn = $('').addClass("srtBtn").text("View Plain Text").data("fmt", "txt").appendTo($btnsContainer);
var $srt = $('').addClass('srt').html(txt.replace(/\n/g, "
")).appendTo($txtContainer);
$txtContainer.appendTo($parent).slideDown();
});
});
});
$('.padmaBtn').live("click", function() {
var padmaId = $(this).parents(".container").attr("data-padma");
window.open("http://powertapes.pad.ma/" + padmaId);
});
$('.srtBtn').live("click", function() {
var fmt = $(this).data("fmt");
var srt = $(this).parents(".srtContainer").data("srt");
var txt = srtToTxt(srt, fmt);
txt = txt.replace(/\n/g, "
");
$(this).parents(".srtContainer").find(".srt").html(txt);
});
var srtToTxt = function(txt, fmt) {
if (fmt == 'srt') return txt;
var that = this;
var 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 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 npt2ms(npt) {
var ms = 0.0
npt = String(npt);
var p = npt.split(':')
for(i=0;i