Home > Programming > Download all files in RSS feed using Ruby

Download all files in RSS feed using Ruby

I’m working on learning Ruby on Rails and one great resource that I find myself going to is RailsCast. But as I really need to learn Ruby I wanted to write a quick program to download all the episodes to my harddisk and watch them using Plex Media Center. There’s probably a million different utilities (or podcast managers) that can do that, but using them I won’t learn to program Ruby that way. There’s probably a better way of doing this, but hey, do it and post a comment.

require 'rubygems'
require 'hpricot'
require 'open-uri'

doc = Hpricot.XML(open("http://feeds.feedburner.com/railscasts"))

(doc/"enclosure").each do |para|
  filename = File.basename(para[:url])
  puts "== Found a file #{filename}"
  open(filename,"w").write(open(para[:url]).read)
end
Categories: Programming Tags: ,
  1. Peter Olsson
    April 24th, 2009 at 22:01 | #1

    Va?

  2. Jacken
    April 25th, 2009 at 06:28 | #2

    Hehe, du är rolig du Peter

  3. Jacken
    April 25th, 2009 at 06:29 | #3

    Men skaffa för fan en gravatar. Tryck på Gravatar bilden och regga dig. Det är ju hela din framställning på nätet som står på spel…