| 1 | package com.longtailvideo.jwplayer.parsers { |
|---|
| 2 | |
|---|
| 3 | import com.longtailvideo.jwplayer.model.PlaylistItem; |
|---|
| 4 | import com.longtailvideo.jwplayer.utils.Strings; |
|---|
| 5 | |
|---|
| 6 | /** |
|---|
| 7 | * Parse an ATOM feed and translate it to a feedarray. |
|---|
| 8 | **/ |
|---|
| 9 | public class ATOMParser implements IPlaylistParser { |
|---|
| 10 | |
|---|
| 11 | /** Parse an RSS playlist for feeditems. **/ |
|---|
| 12 | public function parse(dat:XML):Array { |
|---|
| 13 | var arr:Array = new Array(); |
|---|
| 14 | for each (var i:XML in dat.children()) { |
|---|
| 15 | if (i.localName().toLowerCase() == 'entry') { |
|---|
| 16 | arr.push(parseItem(i)); |
|---|
| 17 | } |
|---|
| 18 | } |
|---|
| 19 | return arr; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | /** Translate ATOM item to playlist item. **/ |
|---|
| 23 | public function parseItem(obj:XML):PlaylistItem { |
|---|
| 24 | var itm:Object = new Object(); |
|---|
| 25 | for each (var i:XML in obj.children()) { |
|---|
| 26 | switch (i.localName().toLowerCase()) { |
|---|
| 27 | case 'author': |
|---|
| 28 | itm['author'] = i.children()[0].text().toString(); |
|---|
| 29 | break; |
|---|
| 30 | case 'title': |
|---|
| 31 | itm['title'] = i.text().toString(); |
|---|
| 32 | break; |
|---|
| 33 | case 'summary': |
|---|
| 34 | itm['description'] = i.text().toString(); |
|---|
| 35 | break; |
|---|
| 36 | case 'link': |
|---|
| 37 | if (Strings.xmlAttribute(i, 'rel') == 'alternate') { |
|---|
| 38 | itm['link'] = Strings.xmlAttribute(i, 'href'); |
|---|
| 39 | } else if (Strings.xmlAttribute(i, 'rel') == 'enclosure') { |
|---|
| 40 | itm['file'] = Strings.xmlAttribute(i, 'href'); |
|---|
| 41 | } |
|---|
| 42 | break; |
|---|
| 43 | case 'published': |
|---|
| 44 | itm['date'] = i.text().toString(); |
|---|
| 45 | break; |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | itm = MediaParser.parseGroup(obj, itm); |
|---|
| 49 | itm = JWParser.parseEntry(obj, itm); |
|---|
| 50 | return new PlaylistItem(itm); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | } |
|---|