(function (Popcorn) {
/**
+ * TTXT popcorn parser plug-in
+ * Parses subtitle files in the TTXT format.
+ * Style information is ignored.
+ * Data parameter is given by Popcorn, will need an xml.
+ * Xml is the file contents to be parsed as a DOM tree
*
- *
+ * @param {Object} data
+ *
+ * Example:
+ <TextSample sampleTime="00:00:00.000" text=""></TextSample>
*/
Popcorn.parser( "parseTTXT", "TTXT", function( data ) {
var t = t_in.split(":");
var time = 0;
- try {
- var s = t[2].split('.');
-
- time += parseFloat(t[0], 10)*60*60; // hours => seconds
- time += parseFloat(t[1], 10)*60; // minutes => seconds
- time += parseFloat(s[0], 10);
- time += parseFloat(s[1], 10)/1000;
+ try {
+ return parseFloat(t[0], 10)*60*60 + parseFloat(t[1], 10)*60 + parseFloat(t[2], 10);
} catch (e) { time = 0; }
return time;
};
// this is where things actually start
- // Timings should start at second element, but don't assume can jump right to children[1]
-
var node = data.xml.lastChild.lastChild; // Last Child of TextStreamHeader
var lastStart = 3.4028235e+38;
var cmds = [];
var expects = 8,
count = 0,
- key,
numSubs = 0,
poppercorn = Popcorn( "#video" ),
subs = { // Expected values
"0": "",
- "3": "[Background Music Playing]",
- "6": "",
- "16": "Heay!!",
- "18": "",
- "26": "[Bird noises]",
- "31": ""
+ "2.4": "[Background Music Playing]",
+ "5.2": "",
+ "15.712": "Heay!!",
+ "17.399": "",
+ "25.712": "[Bird noises]",
+ "30.399": ""
};
function plus() {
}
}
- poppercorn.parseTTXT("data/data.ttxt");
+ poppercorn.parseTTXT(document.getElementById('video').getAttribute('data-timeline-sources'));
expect(expects);
Popcorn.forEach(poppercorn.getTrackEvents(), function(evt) {
if(evt._natives.type === "subtitle") {
numSubs++;
- key = Math.ceil(evt.start).toString();
- equals(subs[key], evt.text , "Correct amounts" );
+ equals(subs[evt.start.toString()], evt.text , "Correct text" );
plus();
}
});