source: trunk/as3/com/jeroenwijering/parsers/RSSParser.as @ 1

Revision 1, 1.6 KB checked in by jeroen, 5 years ago (diff)

initial commit of old repository into public one

  • Property svn:executable set to *
Line 
1/**
2* Parse an RSS feed and translate it to a feedarray.
3**/
4package com.jeroenwijering.parsers {
5
6
7import com.jeroenwijering.parsers.MediaParser;
8import com.jeroenwijering.parsers.ObjectParser;
9import com.jeroenwijering.utils.Strings;
10
11
12public class RSSParser extends ObjectParser {
13
14
15        /** Parse an RSS playlist for feeditems. **/
16        public static function parse(dat:XML):Array {
17                var arr = new Array();
18                var itm = new Object();
19                for each (var i in dat.children()) {
20                        if (i.localName() == 'channel') {
21                                for each (var j in i.children()) {
22                                        if(j.name() == 'item') {
23                                                itm = RSSParser.parseItem(j);
24                                        }
25                                        if(itm['type'] != undefined) {
26                                                arr.push(itm);
27                                        }
28                                }
29                        }
30                }
31                return arr;
32        };
33
34
35        /** Translate RSS item to playlist item. **/
36        public static function parseItem(obj:XML):Object {
37                var itm =  new Object();
38                for each (var i in obj.children()) {
39                        switch(i.localName()) {
40                                case 'duration':
41                                        itm['duration'] = Strings.seconds(i.text());
42                                        break;
43                                case 'enclosure':
44                                        itm['file'] = i.@url.toString();
45                                        itm['type'] = i.@type.toString();
46                                        break;
47                                case 'title':
48                                        itm['title'] = i.text().toString();
49                                        break;
50                                case 'description':
51                                        itm['description'] = i.text().toString();
52                                        break;
53                                case 'summary':
54                                        itm['description'] = i.text().toString();
55                                        break;
56                                case 'link':
57                                        itm['link'] = i.text().toString();
58                                        break;
59                                case 'author':
60                                        itm['author'] = i.text().toString();
61                                        break;
62                                case 'group':
63                                        itm = MediaParser.parseGroup(i,itm);
64                                        break;
65                        }
66                }
67                itm = MediaParser.parseGroup(obj,itm);
68                return ObjectParser.detect(itm);
69        };
70
71
72}
73
74
75}
Note: See TracBrowser for help on using the repository browser.