Skip to content

Instantly share code, notes, and snippets.

@markbrown4
Created October 2, 2012 07:52
Show Gist options
  • Save markbrown4/3817151 to your computer and use it in GitHub Desktop.
Save markbrown4/3817151 to your computer and use it in GitHub Desktop.
railscast downloader
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://railscasts.com/?type=free"))
total_pages = doc.css('.pagination a:nth-last-child(2)').inner_html.to_i
(1..total_pages).each do |i|
puts "PAGE #{i} ================================"
doc = Nokogiri::HTML(open("http://railscasts.com/?type=free&page=#{i}"))
doc.css('.episode').each do |episode|
href = episode.css('.watch a:first-child')[0]['href'].split('?')[0]
filename = href.split('/').last + '.m4v'
download_url = "/assets/episodes/videos/#{filename}"
filepath = File.dirname(__FILE__) + "/videos/" + filename
unless File.exist?(filepath)
puts "Downloading #{filename}"
Net::HTTP.start('media.railscasts.com', 80) { |http|
resp = http.get(download_url)
open(filepath, "wb") { |file|
file.write(resp.body)
}
}
end
end
puts "================================"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment