Skip to content

Instantly share code, notes, and snippets.

@searchzakir
Forked from jmazzi/peepcode.rb
Created July 29, 2012 22:05
Show Gist options
  • Save searchzakir/3202099 to your computer and use it in GitHub Desktop.
Save searchzakir/3202099 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 = File.expand_path 'downloads'
@wget_cookie = File.expand_path(File.dirname(__FILE__)) + '/wget-cookies.txt'
unless File.directory? @download_path
puts "@{download_path} doesn't exist!"
exit
end
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')
cmd = "wget --no-check-certificate --keep-session-cookies --save-cookies wget-cookies.txt "
cmd<< "--post-data 'email=#{@username}&password=#{@password}' https://peepcode.com/sessions"
system cmd
end
system "cd #{@download_path}; wget --load-cookies #{@wget_cookie} --continue '#{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|
ogg = dl.href.match(/\.ogg/)
s3 = (dl.text.match(/USA-West/) || dl.href.match(/s3=true/))
wmv = dl.href.match(/wmv_zip/)
if !s3 && !ogg && !links.include?(dl.href) && !wmv
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