Skip to content

Instantly share code, notes, and snippets.

@gertig
Forked from jmazzi/peepcode.rb
Created August 18, 2011 20:40
Show Gist options
  • Save gertig/1155142 to your computer and use it in GitHub Desktop.
Save gertig/1155142 to your computer and use it in GitHub Desktop.
A script to download all Peepcode screencasts with ruby & wget (supports resume)
require 'mechanize'
@username = '[email protected]'
@password = 'hi2u'
@download_path = '/Users/username/peepcode/downloads'
agent = Mechanize.new
agent.cookie_jar.load('cookies.yml') if File.exists?('cookies.yml')
page = agent.get 'https://peepcode.com/'
unless page.body.match /\/peepers\/account\/edit/
puts "Logging in"
page = agent.get 'https://peepcode.com/login'
signin_form = page.form_with(:action => '/sessions')
signin_form.email = @username
signin_form.password = @password
agent.submit(signin_form, signin_form.buttons.first)
agent.cookie_jar.save_as('cookies.yml')
end
def wget(path)
unless File.exists?('wget-cookies.txt')
system "wget --no-check-certificate --keep-session-cookies --save-cookies wget-cookies.txt --post-data 'email=#{@username}&password=#{@password}' https://peepcode.com/sessions"
end
system "cd #{@download_path}; wget --load-cookies ../wget-cookies.txt '#{path}'"
end
page = agent.get 'https://peepcode.com/products'
page.links_with(:href => %r{/products/}).each do |link|
puts "Processing #{link.text}"
result = agent.click link
links = []
download_links = result.links_with(:href => %r{/unlimited_downloads/}).each do |dl|
if !dl.text.match(/USA-West/) && !dl.href.match(/\.ogg/) && !dl.href.match(/s3=true/) && !links.include?(dl.href)
links.push dl.href
wget dl.href
end
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment