Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alobato
Forked from tmilewski/railscasts.rb
Created February 25, 2013 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alobato/5034006 to your computer and use it in GitHub Desktop.
Save alobato/5034006 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'hpricot'
require 'open-uri'
doc = open('http://railscasts.com/') { |f| Hpricot(f) }
total_episodes = (doc/'div.number').first.inner_html[1,3].to_i
total_pages = (total_episodes / 10).ceil
(1..total_pages).each do |i|
puts "PAGE #{i} ================================"
doc = open("http://railscasts.com/?page=#{i}") { |f| Hpricot(f) }
(doc/'div.episode').each do |episode|
puts "#{episode.at('div.number').inner_html} - #{episode.at('h2/a').inner_html}"
media = episode.at('div.download/a')['href'].scan(/http:\/\/(.*)\/videos(\S*)/)[0]
Net::HTTP.start(media[0]) { |http|
resp = http.get("/videos/#{media[1]}")
open("/Volumes/External\ HD/Tutorials/#{media[1]}", "wb") { |file|
file.write(resp.body)
}
}
puts "================================"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment