Easy way to extract urls out of a podcast rss feed?

Heyas.

I’m writing an app for a podcast I’m a host in.

I’d like to point the app to the RSS feed of the podcast and rip out any url from the RSS feed thus:

<enclosure type="audio/mpeg" url="http://techwebcast.podomatic.com/enclosure/2011-08-07T01_00_52-07_00.mp3" length="9218958"></enclosure>

Then try to play it inside Corona somehow.
The URL for the podcast RSS feed is:
http://techwebcast.podomatic.com/rss2.xml
Is there an easy way to download the xml and parse out just the mp3 without going into difficult XML parsing?

I’d ideally like to make a UI table of buttons to press to play each episode of the show.

Cheers! :slight_smile: [import]uid: 10389 topic_id: 13462 reply_id: 313462[/import]

if you want to list all the episodes and play it separately then you have to parse the XML document. let me see whether I can find you some simple code for that. [import]uid: 71210 topic_id: 13462 reply_id: 49427[/import]

In the Corona SDK blog, there was a recent post about parsing XML files and there are exiting libraries that make it reasonably easy.

In fact I’m building an App for my older son’s Music Blog and I’ve got it to a point where I can read the entries with podcasts and extract out the URL. I’m now stuck (translate to: being lazy) on creating a player to play it.

local xml = require( "xml" ).newParser()  
  
local stories = {}  
  
local networkListener = function( event )  
 local feed  
 local story = {}  
 if ( event.isError ) then  
 print ( "Network error - download failed" )  
 story.title = "Network Error"  
 story.link = nil  
 stories[1] = story  
 else  
 print("Parsing the feed")  
 feed = xml:loadFile("index.rss", system.TemporaryDirectory)  
 local items = feed.child[1].child  
 local i  
 local l = 1  
 for i = 1, #items do  
 local item = items[i]  
 if item.name == "item" then -- we have a story batman!  
 local j  
 for j = 1, #item.child do  
 if item.child[j].name == "title" then  
 story.title = item.child[j].value  
 end  
 if item.child[j].name == "link" then  
 story.link = item.child[j].value  
 end  
 if item.child[j].name == "pubDate" then  
 story.pubDate = item.child[j].value  
 end  
 if item.child[j].name == "content:encoded" then  
 -- get the story body  
 bodytag = {}  
 bodytag = item.child[j].child  
 utility.print\_r(bodytag)  
 local p;  
 story.body = ""  
 for p = 1, #bodytag do  
 if (bodytag[p].value) then  
 story.body = story.body .. bodytag[p].value .. "\n\n"  
 end  
 end  
 end  
 if item.child[j].name == "enclosure" then  
 local properties = {}  
 properties = item.child[j].properties  
 story.podcastURL = properties.url  
 story.podcastSize = properties.length  
 story.podcastType = properties.type  
 end  
 end  
 stories[l] = {}  
 stories[l].link = story.link  
 stories[l].title = story.title  
 stories[l].body = story.body  
 stories[l].podcastURL = story.podcastURL  
 stories[l].podcastSize = story.podcastSize  
 stories[l].podcastType = story.podcastType  
 -- print("[[" .. story.body .. "]]")  
 l = l + 1  
 end  
 end  
 end  
end  
  
network.download("http://yoursite.com/feed/", "GET", networkListener, "index.rss", system.TemporaryDirectory )  

This seems to be working for me! I should note that I haven’t tested this well. Also the blog I’m fetching from makes heavy use of special characters for quotes, mdashes, etc. And the XML library I’m using chokes on them, so I’ve been hacking it to convert them to ASCII on the fly.
[import]uid: 19626 topic_id: 13462 reply_id: 49617[/import]

Thanks for the help! [import]uid: 10389 topic_id: 13462 reply_id: 49620[/import]

@rob

How do you display the rss feed, text or in a tableView -> slideView?

[import]uid: 13560 topic_id: 13462 reply_id: 50784[/import]

I’m using a widget.tableView, then I made my own screen to show the individual story.
[import]uid: 19626 topic_id: 13462 reply_id: 50785[/import]

I was just a few days ago thinking of trying this on my wordpress website, wanted to check this out for some time now but thought xml was too messy to work with after I played with json.
I think a sample like this should ship with Corona. [import]uid: 13560 topic_id: 13462 reply_id: 50791[/import]

Yea, once you get used to JSON XML is a pain in the pattotie. But RSS is XML, and that’s what wordpress gives us for free, so…

I probably should release the whole project too. Probably more beneficial to the community as source than it is any form of IP.

[import]uid: 19626 topic_id: 13462 reply_id: 50793[/import]

That’d be SO AWESOME! :slight_smile: [import]uid: 10389 topic_id: 13462 reply_id: 50828[/import]

Okay. I fiddled around using Jon’s tutorial and managed to PRINT the correct field values to the terminal.
Next, I’ll get the lines of code above to download the RSS XML file to the temp dir to process.
After that is creating buttons to click to play them.
Coming along nicely.
Might grab some process from above to clean mine up a bit tho. [import]uid: 10389 topic_id: 13462 reply_id: 50992[/import]

This could be a problem, however:

https://www.google.com/calendar/feeds/techwebcast%40gmail.com/public/basic

No file.xml to download. Hmm. [import]uid: 10389 topic_id: 13462 reply_id: 50993[/import]

Oh! This might help. Will test later tonight:

destFilename [import]uid: 10389 topic_id: 13462 reply_id: 50996[/import]

Well I did it. After I submitted the app to Apple, I added the source (Lua) files to the github repository (after making it generic).

No laughing at my code!!!

https://github.com/robmiracle/rss.lua

I didn’t provide any artwork. For the tab bar buttons, find it in code exchange and get your buttons from there. You can make your own bullet for your tableView controllers, provide your own fonts and such.

Now if you want me to do everything for you, you can paypal me some cash-oly! A guy’s got to eat!

:slight_smile:

Enjoy
Rob [import]uid: 19626 topic_id: 13462 reply_id: 51025[/import]

I downloaded your code, got all images and tried it with the Ansca blog rrs feed but I got this error;

ERROR: The resource file () could not be found at case-sensitive path (/var/folders/l0/td5hb8v560j8ncjymmw0btj00000gn/T/TemporaryItems/191/). WARNING: Failed to find image() Runtime error ?:0: attempt to index a nil value stack traceback: [C]: ? ?: in function <?:4683> ?: in function 'renderItem' ?: in function 'sync' ...8ncjymmw0btj00000gn/T/TemporaryItems/191/screen1.lua:92: in function 'processRSSFeed' ...8ncjymmw0btj00000gn/T/TemporaryItems/191/screen1.lua:105: in function <...8ncjymmw0btj00000gn><br>

Is it the index.rss file that causes this, is it just a temp file? From what I can see there is no file like such, I even tried with a bunch of random wordpress blogs since you created this app for one.

After a few tries I created an index.rss file and copied the rss feed from ansca site but I still get the same error.

I can’t figure out what’s wrong? [import]uid: 34126 topic_id: 13462 reply_id: 51114[/import] </…8ncjymmw0btj00000gn>

Did you download the widget library files?

http://developer.anscamobile.com/content/widget

the zip file listed on that page needs to be unpacked in your project folder. I ran into an error and I ended up with:

+--\>My Project/  
 main.lua   
 widget\_ios/  
 tableView/  
 uiButton/  
 tableView/  
 uiButton/  

Make sure you have those resources.
[import]uid: 19626 topic_id: 13462 reply_id: 51120[/import]

I got all the files from your git project, got widget_ios, got the graphics from the tabBar sample, created a 4th tab since you had that in your code and named it accordingly.

I had missed the the “bullet image” but I made one myself with the same size.

So now I ran the sample again and got this error;

Runtime error  
 ...60j8ncjymmw0btj00000gn/T/TemporaryItems/191/main.lua:81: ERROR: ads.init() requires a listener as the last argument.  
stack traceback:  
 [C]: ?  
 [C]: in function 'init'  
 ...60j8ncjymmw0btj00000gn/T/TemporaryItems/191/main.lua:81: in main chunk  
Runtime error: ...60j8ncjymmw0btj00000gn/T/TemporaryItems/191/main.lua:81: ERROR: ads.init() requires a listener as the last argument.  
stack traceback:  
 [C]: ?  
 [C]: in function 'init'  
 ...60j8ncjymmw0btj00000gn/T/TemporaryItems/191/main.lua:81: in main chunk  
  

The weird thing is that I have not altered your code what so ever, I added images with the same names and sizes and I ran it with the Ansca Blog RSS URLs. It’s the first time I get the error above.

The only thing I don’t have is your font but that can be replace with anything.

I mean, it should work since I have all assets and files in the right order? [import]uid: 34126 topic_id: 13462 reply_id: 51122[/import]

That’s odd. ads.init() doesn’t require a call back.

What version are you building with? The ads API isn’t available on iOS (Mac) until build 556 and for Android until 591 (Windows/Mac). If you’re not running those builds or later, I would set the appID to nil (and for good measure set _G.appID to nil as well, so the code doesn’t try to call the ad module.

[import]uid: 19626 topic_id: 13462 reply_id: 51124[/import]

@rob
Great work!
One thing you might wanna be aware of is when the client write a title that is long it wont fit in the headlineBox. A way to fix that would be to have the text size adjust to headlineBox bounds if that is possible or have the headline appear above the content inside of the textbox.
@holmes
I tried with the ansca blog and it worked for me.
[import]uid: 13560 topic_id: 13462 reply_id: 51171[/import]

I thought I was chopping the headline at around 22 characters since they are frequently too long in the tableView. On the individual pages, I gave it two lines worth of space and with the being a native.textBox it has scrolling.

This is a first pass. I’m probably going to end up redoing it in Objective C so I can background the audio for the podcasts since I doubt that’s on Ansca’s roadmap anytime soon.

[import]uid: 19626 topic_id: 13462 reply_id: 51172[/import]

I just tested this on my website and it didn’t work, really odd because I tried several other random sites and they worked fine. I got a feedburner too but didn’t fix the error, I think it can’t parse the feed.

I’m a little too tired to fix the error now, I will deal with it tomorrow.

before I forget, since it’s a little delay when the feeds are downloading maybe the feeds could be downloaded right on app start. [import]uid: 13560 topic_id: 13462 reply_id: 51175[/import]