| Revision 135,
1.3 KB
checked in by jeroen, 4 years ago
(diff) |
|
several bugfixes and the ability to restrict files from start to duration
|
| Line | |
|---|
| 1 | /** |
|---|
| 2 | * Parse an ATOM feed and translate it to a feedarray. |
|---|
| 3 | **/ |
|---|
| 4 | package com.jeroenwijering.parsers { |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | import com.jeroenwijering.parsers.MediaParser; |
|---|
| 8 | import com.jeroenwijering.utils.Strings; |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | public class ATOMParser { |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | /** Parse an RSS playlist for feeditems. **/ |
|---|
| 15 | public static function parse(dat:XML):Array { |
|---|
| 16 | var arr:Array = new Array(); |
|---|
| 17 | for each (var i:XML in dat.children()) { |
|---|
| 18 | if (i.localName() == 'entry') { |
|---|
| 19 | arr.push(ATOMParser.parseItem(i)); |
|---|
| 20 | } |
|---|
| 21 | } |
|---|
| 22 | return arr; |
|---|
| 23 | }; |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | /** Translate ATOM item to playlist item. **/ |
|---|
| 27 | public static function parseItem(obj:XML):Object { |
|---|
| 28 | var itm = new Object(); |
|---|
| 29 | for each (var i:XML in obj.children()) { |
|---|
| 30 | switch(i.localName()) { |
|---|
| 31 | case 'author': |
|---|
| 32 | itm['author'] = i.children()[0].text().toString(); |
|---|
| 33 | break; |
|---|
| 34 | case 'title': |
|---|
| 35 | itm['title'] = i.text().toString(); |
|---|
| 36 | break; |
|---|
| 37 | case 'summary': |
|---|
| 38 | itm['description'] = i.text().toString(); |
|---|
| 39 | break; |
|---|
| 40 | case 'link': |
|---|
| 41 | if(i.@rel == 'alternate') { |
|---|
| 42 | itm['link'] = i.@href.toString(); |
|---|
| 43 | } else if (i.@rel == 'enclosure') { |
|---|
| 44 | itm['file'] = i.@href.toString(); |
|---|
| 45 | } |
|---|
| 46 | break; |
|---|
| 47 | case 'published': |
|---|
| 48 | itm['date'] = i.text().toString(); |
|---|
| 49 | break; |
|---|
| 50 | case 'group': |
|---|
| 51 | itm = MediaParser.parseGroup(i,itm); |
|---|
| 52 | break; |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | itm = MediaParser.parseGroup(obj,itm); |
|---|
| 56 | return itm; |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.