]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#291] Error checking, null tests
authorstevenaw <sweerdenburg@gmail.com>
Thu, 27 Jan 2011 16:16:00 +0000 (11:16 -0500)
committerstevenaw <sweerdenburg@gmail.com>
Thu, 27 Jan 2011 16:16:00 +0000 (11:16 -0500)
parsers/parserVTT/data/data.vtt
parsers/parserVTT/data/unit.vtt
parsers/parserVTT/popcorn.parserVTT.js
parsers/parserVTT/popcorn.parserVTT.unit.html
parsers/parserVTT/popcorn.parserVTT.unit.js

index 6ef05aac1718c30af8743b96b9b4d187e6004e40..5d74f548233cd7ee34345825abfce99e49947060 100644 (file)
@@ -6,3 +6,7 @@ our final approach into Coruscant.
 2
 00:00:9.712 --> 00:00:13.399
 Very good, Lieutenant.
+
+Track-3
+00:00:15.542 --> 00:00:18.542 A:start D:vertical L:98%
+It's a trap!
index a4c306517b15272b3635fa097b26c2195eb33d43..2d5a606e532c6c0be57140c2b4edd8e210a496c4 100644 (file)
@@ -1,14 +1,39 @@
 1
-00:00:02.400 --> 00:00:07.200
+00:00:02.400   -->    00:00:07.200
 Senator, we're making
 our final approach into Coruscant.
 
 2
-00:9.712 --> 00:13.399
+00:09.712-->00:13.399
 Very good, Lieutenant.
 
 
 
+3
+00:00:13.400 --> 00:00:20
+A bad cue, no milliseconds. Should be ignored
+
+-->
+00:00:14.456--> 00:00:20.000
+A bad cue, bad id. Should be ignored
+
+4
+00:00:9.456--> 00:00:20.000
+A bad cue, seconds are single digit. Should be ignored
+
+5
+00:1:00.456--> 00:00:20.000
+A bad cue, minutes are single digit. Should be ignored
+
+6
+1:00:00.456--> 00:00:20.000
+A bad cue, hours are supplied as single digit. Should be ignored
+
+7
+00:00:00.46--> 00:00:20.000
+A bad cue, ms are not 3 digits. Should be ignored
+
 Track-3
 00:00:15.042 --> 00:00:18.042 A:start D:vertical L:98%
 It's a trap!
+
index 8583d6e8e515415323826d147d48ac4e0bf431e0..cf0248aa3d151e33342fa4ba17102db325d15bcc 100644 (file)
@@ -2,23 +2,27 @@
 
 (function (Popcorn) {
   Popcorn.parser( "parseVTT", "VTT", function( data ) {
-
+  
     // declare needed variables
     var retObj = {
           title: "",
           remote: "",
           data: []
         },
-        subs = [],
-        lines,
+        lines, time, text, sub,
+        subs = [],        
         i = 0, len = 0, idx = 0;
     
-    // [HH]:MM:SS.mmm string to SS.mmm
+    // [HH:]MM:SS.mmm string to SS.mmm float
+    // Throws exception if invalid
     var toSeconds = function(t_in) {
       var t = t_in.split(':');
-      var time, l = t.length-1;
+      var time, l = t_in.length;
       
-      try {
+      if (l !== 12 && l !== 9) throw "Bad cue";
+      l = t.length - 1;
+      
+      try {        
         time = parseInt(t[l-1], 10)*60 + parseFloat(t[l], 10);
         
         if (l === 2) // Hours given
     len = lines.length;
     
     while (i < len) {
-      var sub = {};
-      
-      sub.id = lines[i++];
-      
-      var time = lines[i++].split(" --> ");
-      var text = [];
+      sub = {};
+      text = [];
       
       try {
+        sub.id = lines[i++];
+        
+        if (!sub.id || sub.id.indexOf("-->") !== -1) throw "Bad cue";
+        
+        time = lines[i++].split(/[\t ]*-->[\t ]*/);
+        
         sub.start = toSeconds(time[0]);
         
         // Filter out any trailing styling info
index b4204fe20b3a8dcb6b447508e2ab7886f20d35e5..a9b668342b57dbe31e4c2401c32ad856c486e595 100644 (file)
@@ -26,6 +26,7 @@ popcorn-api-draft.js
   <video id='video'
     controls
     width= '250px'
+    data-timeline-sources="data/unit.vtt"
     poster="../../test/poster.png">
 
     <source id='mp4'
index 2fbcff04b31143490899d1a8d837737bac24f102..77a639ee43de1e1306268a840e4549ca1d0b563a 100644 (file)
@@ -30,11 +30,11 @@ test("Popcorn 0.3 VTT Parser Plugin", function () {
     }
   }
   
-  poppercorn.parseVTT("data/unit.vtt");
+  poppercorn.parseVTT(document.getElementById('video').getAttribute('data-timeline-sources'));
   
   expect(expects);
   
-  stop( 10000 );
+  stop( 5000 );
   
   // Allow load time
   setTimeout(function () {