[xiph-commits] r3961 - in itext: . javascript
silvia at svn.annodex.net
silvia at svn.annodex.net
Tue Jul 21 00:07:14 PDT 2009
Author: silvia
Date: 2009-07-21 00:07:14 -0700 (Tue, 21 Jul 2009)
New Revision: 3961
Modified:
itext/
itext/javascript/subtitles.js
Log:
Cleaning up of file handling and separating out srt parsing.
Property changes on: itext
___________________________________________________________________
Modified: bzr:revision-info
- timestamp: 2009-07-18 22:36:22.602999926 +1000
committer: Silvia Pfeiffer <silvia.pfeiffer at vquence.com>
properties:
branch-nick: silvia
+ timestamp: 2009-07-18 23:16:44.624000072 +1000
committer: Silvia Pfeiffer <silvia.pfeiffer at vquence.com>
properties:
branch-nick: silvia
Modified: bzr:file-ids
- skins/schmucker/tinyvid.js tinyvid.js-20090718094218-d45036mvytq5pecp-53
+ 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
6 silvia.pfeiffer at vquence.com-20090718095409-p6en5qufj62m8w3h
7 silvia.pfeiffer at vquence.com-20090718113424-9s8cmt1guxj6qoky
8 silvia.pfeiffer at vquence.com-20090718113445-n0q9c14w4i11pe36
9 silvia.pfeiffer at vquence.com-20090718123622-xdp52y76dvpem2ya
+ 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
7 silvia.pfeiffer at vquence.com-20090718113424-9s8cmt1guxj6qoky
8 silvia.pfeiffer at vquence.com-20090718113445-n0q9c14w4i11pe36
9 silvia.pfeiffer at vquence.com-20090718123622-xdp52y76dvpem2ya
10 silvia.pfeiffer at vquence.com-20090718131644-69y0zml0ccbwc5er
Modified: bzr:text-parents
-
+ javascript/subtitles.js silvia.pfeiffer at vquence.com-20090718113424-9s8cmt1guxj6qoky
Modified: itext/javascript/subtitles.js
===================================================================
--- itext/javascript/subtitles.js 2009-07-21 07:07:06 UTC (rev 3960)
+++ itext/javascript/subtitles.js 2009-07-21 07:07:14 UTC (rev 3961)
@@ -345,39 +345,8 @@
}
};
-
-// class to deal with srt
-// could be done in a library if necessary
-var SrtHandle=function(url, charset) {
- this.init(url, charset);
-};
-$.extend(SrtHandle.prototype, {
- url:null,
- html:null,
- textElements: [],
- init:function(url, charset){
- this.load(url, charset);
- },
- load:function(url, charset){
- this.url = url;
- srthandle = this;
- // set the character encoding before the ajax request
- jQuery.ajaxSetup({
- 'beforeSend' : function(xhr) {
- xhr.overrideMimeType ("text/text; charset="+charset);
- }
- });
- jQuery.ajax( {
- type: "GET",
- url: url,
- data: {},
- success: function(data, textStatus) { srthandle.parse(data); },
- dataType: 'text',
- async: false,
- cache: false // REMOVE AFTER TESTING: FIXME
- });
- },
- parse:function(data){
+// Function to parse srt file
+function parseSrt (data) {
var srt = data.replace(/\r+/g,''); // remove dos newlines
srt = srt.replace(/^\s+|\s+$/g,''); // trim white space
// get captions
@@ -406,15 +375,15 @@
// parse text content
content = s.slice(2).join("<br/>");
} else {
- // format error
+ // file format error
return;
}
captions.push({start: start, end: end, content: content});
- });
- this.textElements = captions;
- }
-});
+ });
+ return captions;
+};
+
// This is where the implementation of iText starts
// list of potential errors created with iText parsing
ITEXT_ERR = {
@@ -426,6 +395,49 @@
};
+// class to load a file, call the right parsing function,
+// and keep the parsed text segments
+var LoadFile=function(url, charset, type) {
+ this.load(url, charset, type);
+};
+$.extend(LoadFile.prototype, {
+ url:null,
+ textElements: [],
+ error: 0,
+ load:function(url, charset, type){
+ this.url = url;
+ handler = null;
+ content = [];
+ // choose parsing function
+ if (type == "text/srt") {
+ handler = parseSrt;
+ } else {
+ // no handler for given file type
+ this.error = ITEXT_ERR.SRC_NOT_SUPPORTED;
+ }
+ // set the character encoding before the ajax request
+ jQuery.ajaxSetup({
+ 'beforeSend' : function(xhr) {
+ xhr.overrideMimeType ("text/text; charset="+charset);
+ }
+ });
+ jQuery.ajax({
+ type: "GET",
+ url: url,
+ data: {},
+ success: function(data, textStatus) { content = parseSrt(data); },
+ dataType: 'text',
+ async: false,
+ cache: false // REMOVE AFTER TESTING: FIXME
+ });
+ if (!content) {
+ this.error = ITEXT_ERR.PARSE;
+ }
+ this.textElements = content;
+ }
+});
+
+
// class to hold an itext track
var ItextTrack=function(track) {
this.init(track);
@@ -460,11 +472,13 @@
fetch:function(src){
if (src) {
this.src = src;
- if (this.type == "text/srt") {
- this.allText = new SrtHandle(src, this.charset).textElements;
+ if (this.type != "text/srt") {
+ this.error = ITEXT_ERR.SRC_NOT_SUPPORTED;
+ } else {
+ file = new LoadFile(src, this.charset, this.type);
+ this.error = file.error;
+ this.allText = file.textElements;
this.fetched = true;
- } else {
- this.error = ITEXT_ERR.SRC_NOT_SUPPORTED;
}
}
},
More information about the commits
mailing list