I had a few moments today to get reacquainted with Ruby and Rails programming. It has been a while but I have found time to watch the occasional Railscast. I want to watch these videos while on the move but unfortunately the iTunes podcasts are not compatible with the iPad/iPhone. Downloading each one is tedious so I came up with the following:
require 'open-uri'
require 'hpricot'
(1..6).each do |page|
doc = Hpricot(open("http://railscasts.com/episodes?page=#{page}"))
(doc/"a").each do |l|
href = l[:href]
if href =~ /.*ipod_videos.*/ then
file_name = File.basename(href)
unless File.exist?(file_name) then
puts "Downloading #{file_name}"
File.open(File.basename(href), "w") do |file|
file.write(open(href).read)
end
end
end
end
end