[xiph-commits] r3957 - in itext: . javascript

silvia at svn.annodex.net silvia at svn.annodex.net
Tue Jul 21 00:06:45 PDT 2009


Author: silvia
Date: 2009-07-21 00:06:45 -0700 (Tue, 21 Jul 2009)
New Revision: 3957

Modified:
   itext/
   itext/javascript/subtitles.js
Log:
Clean up srt parsing



Property changes on: itext
___________________________________________________________________
Modified: bzr:revision-info
   - timestamp: 2009-07-18 19:47:08.934999943 +1000
committer: Silvia Pfeiffer <silvia.pfeiffer at vquence.com>
properties: 
	branch-nick: silvia

   + timestamp: 2009-07-18 19:54:09.450999975 +1000
committer: Silvia Pfeiffer <silvia.pfeiffer at vquence.com>
properties: 
	branch-nick: silvia

Modified: bzr:file-ids
   - 
   + javascript/subtitles.js	subtitles.js-20090718094218-d45036mvytq5pecp-10

Modified: bzr:revision-id:v4
   - 1 silvia.pfeiffer at vquence.com-20090713110521-cz7evclxohf4rbs2
2 silvia.pfeiffer at vquence.com-20090714003359-apmpuor2ttarph5n
3 silvia.pfeiffer at vquence.com-20090714143931-q6j8ritt91jn5rhu
4 silvia.pfeiffer at vquence.com-20090718094222-58zgcmsg9gggbnt1
5 silvia.pfeiffer at vquence.com-20090718094708-wb83p9u6jr1xlhm6

   + 1 silvia.pfeiffer at vquence.com-20090713110521-cz7evclxohf4rbs2
2 silvia.pfeiffer at vquence.com-20090714003359-apmpuor2ttarph5n
3 silvia.pfeiffer at vquence.com-20090714143931-q6j8ritt91jn5rhu
4 silvia.pfeiffer at vquence.com-20090718094222-58zgcmsg9gggbnt1
5 silvia.pfeiffer at vquence.com-20090718094708-wb83p9u6jr1xlhm6
6 silvia.pfeiffer at vquence.com-20090718095409-p6en5qufj62m8w3h

Added: bzr:text-parents
   + javascript/subtitles.js	silvia.pfeiffer at vquence.com-20090718094222-58zgcmsg9gggbnt1


Modified: itext/javascript/subtitles.js
===================================================================
--- itext/javascript/subtitles.js	2009-07-21 07:06:36 UTC (rev 3956)
+++ itext/javascript/subtitles.js	2009-07-21 07:06:45 UTC (rev 3957)
@@ -379,37 +379,34 @@
 	},
 	parse:function(data){
 	  var srt = data.replace(/\r+/g,''); // remove dos newlines
-	  var captions = [];
-	  var count = 1;
 	  srt = srt.replace(/^\s+|\s+$/g,''); // trim white space
+	  // get captions
+	  var captions = [];
 	  jQuery.each(srt.split('\n\n'), function(i, caption) {
-	    var c = {};
 	    var s = caption.split(/\n/);
-	    var num, timestr, content, start, end;
+	    var content, start, end;
 	    if (s[0].match(/^\d+$/) && s[1].match(/\d+:\d+:\d+/)) {
-	      num = parseInt(s[0],10);
-	 	  count = num + 1;
-	      timestr = s[1];
-	      content = s.slice(2).join("<br/>");
-	    } else {
-	      return;
-	    }
-	    var m;
-	    if (m = timestr.match(
-	        /(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/)) {
-	      start =
+		  // ignore caption number in s[0]
+		  // parse time string
+	      if (s[1].match(/(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/)) {
+	        start =
 	          (parseInt(m[1], 10) * 60 * 60) +
 	          (parseInt(m[2], 10) * 60) +
 	          (parseInt(m[3], 10)) +
 	          (parseInt(m[4], 10) / 1000);
-
-	      end =
+	        end =
 	          (parseInt(m[5], 10) * 60 * 60) +
 	          (parseInt(m[6], 10) * 60) +
 	          (parseInt(m[7], 10)) +
 	          (parseInt(m[8], 10) / 1000);
+	      } else {
+	        // Unrecognized timestring
+	        return;
+	      }
+		  // parse text content
+	      content = s.slice(2).join("<br/>");
 	    } else {
-	      // Unrecognized timestring
+		  // format error
 	      return;
 	    }
 	    captions.push({start: start, end: end, content: content});



More information about the commits mailing list