1 /** The osmplayer namespace. */ 2 var osmplayer = osmplayer || {}; 3 4 /** The parser object. */ 5 osmplayer.parser = osmplayer.parser || {}; 6 7 /** 8 * The rss parser object. 9 * 10 * @return {object} The rss parser. 11 **/ 12 osmplayer.parser.rss = { 13 14 // The priority for this parser. 15 priority: 8, 16 17 // Return if this is a valid youtube feed. 18 valid: function(feed) { 19 feed = feed.replace(/(.*)\??(.*)/i, '$1'); 20 return feed.match(/\.rss$/i) !== null; 21 }, 22 23 // Returns the type of request to make. 24 getType: function(feed) { 25 return 'xml'; 26 }, 27 28 // Returns the feed provided the start and numItems. 29 getFeed: function(feed, start, numItems) { 30 return feed; 31 }, 32 33 // Parse the feed. 34 parse: function(data) { 35 var playlist = { 36 total_rows: 0, 37 nodes: [] 38 }; 39 jQuery('rss channel', data).find('item').each(function(index) { 40 osmplayer.parser.rss.addRSSItem(playlist, jQuery(this)); 41 }); 42 return playlist; 43 }, 44 45 // Parse an RSS item. 46 addRSSItem: function(playlist, item) { 47 playlist.total_rows++; 48 var node = {}, title = '', desc = '', img = '', media = ''; 49 50 // Get the title. 51 title = item.find('title'); 52 if (title.length) { 53 node.title = title.text(); 54 } 55 56 // Get the description. 57 desc = item.find('annotation'); 58 if (desc.length) { 59 node.description = desc.text(); 60 } 61 62 // Add the media files. 63 node.mediafiles = {}; 64 65 // Get the image. 66 img = item.find('image'); 67 if (img.length) { 68 node.mediafiles.image = { 69 image: { 70 path: img.text() 71 } 72 }; 73 } 74 75 // Get the media. 76 media = item.find('location'); 77 if (media.length) { 78 node.mediafiles.media = { 79 media: { 80 path: media.text() 81 } 82 }; 83 } 84 85 // Add this node to the playlist. 86 playlist.nodes.push(node); 87 } 88 }; 89