source: branches/4.2/com/jeroenwijering/parsers/TTParser.as @ 79

Revision 79, 1.1 KB checked in by jeroen, 5 years ago (diff)

fixed a few small bugs (resizing), updated the pdf and added the parsers for TT and SRT

  • Property svn:executable set to *
Line 
1/**
2* Parse a TimedText XML and return an array of captions.
3*
4* The entries in the array look like:
5* []['begin']
6* []['end']
7* []['text']
8*
9**/
10package com.jeroenwijering.parsers {
11
12
13import com.jeroenwijering.utils.Strings;
14
15
16public class TTParser {
17
18
19        /** The supported paragraph elements. **/
20        private static var ELEMENTS:Object = {
21                'begin':undefined,
22                'dur':undefined,
23                'end':undefined,
24                'text':undefined
25        };
26
27
28        /** Parse the cationing array. **/
29        public static function parseCaptions(dat:XML):Array {
30                var arr = new Array();
31                var div = dat.children()[1].children()[0];
32                for each (var i in div.children()) {
33                        if(i.localName() == 'p') {
34                                arr.push(TTParser.parseCaption(i));
35                        }
36                }
37                return arr;
38        };
39
40
41        /** Parse a single captions entry. **/
42        private static function parseCaption(dat:XML):Object {
43                var obj = {
44                        begin:Strings.seconds(dat.@begin),
45                        dur:Strings.seconds(dat.@dur),
46                        end:Strings.seconds(dat.@end),
47                        text:dat.children().toString()
48                };
49                if(obj['dur']) {
50                        obj['end'] = obj['begin'] + obj['dur'];
51                        delete obj['dur'];
52                }
53                return obj;
54        };
55
56
57}
58
59
60}
Note: See TracBrowser for help on using the repository browser.