root/trunk/as2/com/jeroenwijering/feeds/ASXParser.as @ 1

Revision 1, 1.7 kB (checked in by jeroen, 18 months ago)

initial commit of old repository into public one

Line 
1/**
2* Parses ASX feeds and returns an indexed array with all elements
3*
4* @author       Jeroen Wijering
5* @version      1.0
6**/
7
8
9import com.jeroenwijering.feeds.AbstractParser;
10import com.jeroenwijering.utils.StringMagic;
11
12
13class com.jeroenwijering.feeds.ASXParser extends AbstractParser {
14
15
16        /** Contructor **/
17        function ASXParser() { super(); };
18
19
20        /** build an array with all regular elements **/
21        private function setElements() {
22                elements = new Object();
23                elements["title"] = "title";
24                elements["author"] = "author";
25                elements["abstract"] = "description";
26        };
27
28
29        /** Convert RSS structure to array **/
30        private function parse(xml:XML):Array {
31                var arr = new Array();
32                var tpl = xml.firstChild.firstChild;
33                while(tpl != null) {
34                        if (tpl.nodeName.toLowerCase() == "entry") {
35                                var obj = new Object();
36                                for(var j=0; j<tpl.childNodes.length; j++) {
37                                        var nod:XMLNode = tpl.childNodes[j];
38                                        var nnm = nod.nodeName.toLowerCase();
39                                        if(elements[nnm] != undefined) {
40                                                obj[elements[nnm]] = nod.firstChild.nodeValue;
41                                        } else if(nnm == "moreinfo") {
42                                                obj["link"] = nod.attributes.href;
43                                        } else if(nnm == "duration") {
44                                                obj["duration"] =
45                                                        StringMagic.toSeconds(nod.attributes.value);
46                                        } else if(nnm == "ref") {
47                                                obj["file"] = nod.attributes.href;
48                                                var typ = nod.attributes.href.substr(-3);
49                                                if(mimetypes[typ]!=undefined) {
50                                                        obj["type"] = mimetypes[typ];
51                                                }
52                                                if(obj["file"].substr(0,4) == "rtmp") {
53                                                        obj["type"] = "rtmp";
54                                                } else if(obj['file'].indexOf('youtube.com') > -1) {
55                                                        obj["type"] = "youtube";
56                                                }
57                                        } else if(nnm == "param") {
58                                                obj[nod.attributes.name] = nod.attributes.value;
59                                        }
60                                }
61                                arr.push(obj);
62                        }
63                        tpl = tpl.nextSibling;
64                }
65                return arr;
66        };
67
68
69}
Note: See TracBrowser for help on using the browser.