]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Simplified code
authorstevenaw <sweerdenburg@gmail.com>
Wed, 26 Jan 2011 17:59:52 +0000 (12:59 -0500)
committerstevenaw <sweerdenburg@gmail.com>
Wed, 26 Jan 2011 17:59:52 +0000 (12:59 -0500)
parsers/parserVTT/data/unit.vtt
parsers/parserVTT/popcorn.parserVTT.js
parsers/parserVTT/popcorn.parserVTT.unit.js

index ee8c6102f6dd88a6fb142cee84010d2983f7f9ae..a4c306517b15272b3635fa097b26c2195eb33d43 100644 (file)
@@ -7,6 +7,8 @@ our final approach into Coruscant.
 00:9.712 --> 00:13.399
 Very good, Lieutenant.
 
+
+
 Track-3
 00:00:15.042 --> 00:00:18.042 A:start D:vertical L:98%
 It's a trap!
index 9350234bef476ee8e31421105cd241ecd8c69c2b..8583d6e8e515415323826d147d48ac4e0bf431e0 100644 (file)
@@ -11,7 +11,7 @@
         },
         subs = [],
         lines,
-        i = 0, l = 0;
+        i = 0, len = 0, idx = 0;
     
     // [HH]:MM:SS.mmm string to SS.mmm
     var toSeconds = function(t_in) {
     };
   
     // Here is where the magic happens
-    lines = data.text.replace("\r",'').split("\n");
-    l = lines.length;
+    // Split on line breaks
+    lines = data.text.split(/(?:\r\n|\r|\n)/gm);
+    len = lines.length;
     
-    while (i < l) {
+    while (i < len) {
       var sub = {};
       
-      sub.id = lines[i++].replace('\r', '');
+      sub.id = lines[i++];
       
       var time = lines[i++].split(" --> ");
       var text = [];
         sub.start = toSeconds(time[0]);
         
         // Filter out any trailing styling info
-        time[1] = time[1].replace("\r", " ");
-        sub.end = toSeconds(time[1].substr(0, time[1].indexOf(" ")));
+        idx = time[1].indexOf(" ");
+        sub.end = toSeconds(idx === -1 ? time[1] : time[1].substr(0, idx));
         
-        while (lines[i] && lines[i] !== "\r") {
-          text.push(lines[i++].replace("\r", ""));
+        while (i < len && lines[i]) {
+          text.push(lines[i++]);
         }
         
         sub.text = text.join(" ");
         subs.push( createTrack("subtitle", sub) );
       } catch (e) { // Bad cue
-        while (i < l && !lines[i++] !== "\r"); // Advance to end of cue
+        while (i < len && lines[i++]); // Advance to end of cue
       }
       
       // Consume empty whitespace
-      while (i < l && !lines[i++] === "\r");
+      while (i < len && !lines[i]) { i++; }
     }
     
     retObj.data = subs;
index c1e3670d4d5ee96a67dc286768fed4907e5fb512..2fbcff04b31143490899d1a8d837737bac24f102 100644 (file)
@@ -34,7 +34,7 @@ test("Popcorn 0.3 VTT Parser Plugin", function () {
   
   expect(expects);
   
-  stop( 5000 );
+  stop( 10000 );
   
   // Allow load time
   setTimeout(function () {