]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Working
authorstevenaw <sweerdenburg@gmail.com>
Tue, 25 Jan 2011 17:10:44 +0000 (12:10 -0500)
committerstevenaw <sweerdenburg@gmail.com>
Tue, 25 Jan 2011 17:10:44 +0000 (12:10 -0500)
parsers/parserTTXT/popcorn.parseTTXT.html
parsers/parserTTXT/popcorn.parseTTXT.js

index cba680bac5c4ea41634f42c496bc9c2267ba992d..e65d66948ba6957bb302c58a3cf0cd64636b5469 100644 (file)
@@ -5,6 +5,7 @@
   
   <script src="../../popcorn.js"></script>
   <script src="../../test/jquery.js"></script>
+  <script src="../../plugins/subtitle/popcorn.subtitle.js"></script>
   <script src="popcorn.parseTTXT.js"></script>
 
 </head>
index 34678a967780368e4bb0bee0e5e068bc9f129773..db927804d2414e18c073195161a411754b98e49c 100644 (file)
       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;
   });