Created
December 2, 2008 04:31
-
-
Save benschwarz/30996 to your computer and use it in GitHub Desktop.
RubyConf 2008 video scraper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w(rubygems nokogiri open-uri fileutils).each do |r| | |
require r | |
end | |
BASE_URI = "http://rubyconf2008.confreaks.com/" | |
LOCAL_SAVE_PATH = "ruby-videos/" | |
FileUtils.mkdir_p LOCAL_SAVE_PATH | |
puts "Looking..." | |
doc = Nokogiri::HTML(open(BASE_URI)) | |
video_pages = doc.css('td.program a').map{|element| element.attributes['href'] } | |
puts "Hunting and gathering..." | |
videos = video_pages.uniq.map do |page| | |
puts "\tFound #{File.basename(page)}!" | |
vid_doc = Nokogiri::HTML(open(BASE_URI + page)) | |
vid_doc.css('.formatlist a').first.attributes['href'] | |
end | |
puts "Downloading..." | |
videos.each do |vid_path| | |
puts "\tDownloading #{vid_path}..." | |
unless File.exists? LOCAL_SAVE_PATH + File.basename(vid_path) | |
File.open(LOCAL_SAVE_PATH + File.basename(vid_path), 'w') {|f| f.write(open(BASE_URI + vid_path).read) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment