]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#289] Optimizations, further documentation
authorstevenaw <sweerdenburg@gmail.com>
Fri, 28 Jan 2011 22:18:06 +0000 (17:18 -0500)
committerstevenaw <sweerdenburg@gmail.com>
Fri, 28 Jan 2011 22:18:06 +0000 (17:18 -0500)
parsers/parserTTXT/popcorn.parseTTXT.js
parsers/parserTTXT/popcorn.parseTTXT.unit.html
parsers/parserTTXT/popcorn.parseTTXT.unit.js

index 7c946bd162d12ef10c2acebcf949511271750e20..b996c0a9103184456a0428d732655d9c53b2c58f 100644 (file)
@@ -3,8 +3,16 @@
 (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;
@@ -40,8 +43,6 @@
     };
 
     // 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 = [];
index f2eb31cb7b76828333935b98d7d3b7c79c3de13d..0b2ed08c62d1d3910f331be1ae681ae98458081a 100644 (file)
@@ -26,6 +26,7 @@
   <video id='video' 
     controls
     width= '250px'
+    data-timeline-sources="data/data.ttxt"
     poster="../../test/poster.png"> 
 
     <source id='mp4'
index 7f3d9c05ce827573c14265730b0a263e69c2d0ba..c67537a6f259a617d2598a6b30cc018b5aec9a82 100644 (file)
@@ -2,17 +2,16 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
   
   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() {
@@ -21,7 +20,7 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
     }
   }
   
-  poppercorn.parseTTXT("data/data.ttxt");
+  poppercorn.parseTTXT(document.getElementById('video').getAttribute('data-timeline-sources'));
   
   expect(expects);
   
@@ -32,8 +31,7 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
     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();
       }
     });