From: stevenaw Date: Tue, 25 Jan 2011 17:10:44 +0000 (-0500) Subject: Working X-Git-Tag: v0.3~15^2~4^2~3 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=6c60654b62cf437319beae14ef1c5b5c7548a042;p=popcorn-js.git Working --- diff --git a/parsers/parserTTXT/popcorn.parseTTXT.html b/parsers/parserTTXT/popcorn.parseTTXT.html index cba680b..e65d669 100644 --- a/parsers/parserTTXT/popcorn.parseTTXT.html +++ b/parsers/parserTTXT/popcorn.parseTTXT.html @@ -5,6 +5,7 @@ + diff --git a/parsers/parserTTXT/popcorn.parseTTXT.js b/parsers/parserTTXT/popcorn.parseTTXT.js index 34678a9..db92780 100644 --- a/parsers/parserTTXT/popcorn.parseTTXT.js +++ b/parsers/parserTTXT/popcorn.parseTTXT.js @@ -32,89 +32,36 @@ return time; }; - // turns a node tree element into a straight up javascript object - // also converts in and out to start and end - // also links manifest data with ids - /*var objectifyAttributes = function ( nodeAttributes ) { - - var returnObject = {}; - - for ( var i = 0, nal = nodeAttributes.length; i < nal; i++ ) { - - var key = nodeAttributes.item(i).nodeName, - data = nodeAttributes.item(i).nodeValue; - - // converts in into start - if (key === "in") { - returnObject.start = toSeconds( data ); - // converts out into end - } else if ( key === "out" ){ - returnObject.end = toSeconds( data ); - // this is where ids in the manifest are linked - } else if ( key === "resourceid" ) { - Popcorn.extend( returnObject, manifestData[data] ); - // everything else - } else { - returnObject[key] = data; - } - - } - - return returnObject; - };*/ - // creates an object of all atrributes keyed by name var createTrack = function( name, attributes ) { var track = {}; track[name] = attributes; return track; }; -/* - // recursive function to process a node, or process the next child node - var parseNode = function ( node, allAttributes, manifest ) { - var attributes = {}; - Popcorn.extend( attributes, allAttributes, objectifyAttributes( node.attributes ), { text: node.textContent } ); - - var childNodes = node.childNodes; - - // processes the node - if ( childNodes.length < 1 || ( childNodes.length === 1 && childNodes[0].nodeType === 3 ) ) { - - if ( !manifest ) { - returnData.data.push( createTrack( node.nodeName, attributes ) ); - } else { - manifestData[attributes.id] = attributes; - } - - // process the next child node - } else { - - for ( var i = 0; i < childNodes.length; i++ ) { - - if ( childNodes[i].nodeType === 1 ) { - parseNode( childNodes[i], attributes, manifest ); - } - - } - } - };*/ // this is where things actually start - // Timings start as second element, but don't assume can jump right to children[1] - var node = data.xml.documentElement.lastChild; - var last; + // Timings should start at second element, but don't assume can jump right to children[1] - while (node = node.previousSibling) { - var sub = {}; - sub.start = toSeconds(node.getAttribute('sampleTime')); - sub.text = node.getAttribute('text'); - - // Infer end time, ms accuracy - sub.end = last ? (last.start - 0.001) : (3.4028235e+38); - - returnData.data.push( createTrack("subtitle", sub) ); - last = node; + var node = data.xml.lastChild.lastChild; // Last Child of TextStreamHeader + var lastStart = 3.4028235e+38; + var cmds = []; + + while (node) { + if ( node.nodeType === 1 && node.nodeName === "TextSample") { + var sub = {}; + sub.start = toSeconds(node.getAttribute('sampleTime')); + sub.text = node.getAttribute('text'); + + // Infer end time, ms accuracy + sub.end = lastStart; + + cmds.push( createTrack("subtitle", sub) ); + lastStart = sub.start - 0.001; + } + node = node.previousSibling; } + + returnData.data = cmds.reverse(); return returnData; });