Skip to content

Instantly share code, notes, and snippets.

@jmazzi
Created May 24, 2011 13:54
Show Gist options
  • Select an option

  • Save jmazzi/988742 to your computer and use it in GitHub Desktop.

Select an option

Save jmazzi/988742 to your computer and use it in GitHub Desktop.
A script to download all Peepcode screencasts with ruby & wget (supports resume)
require 'mechanize'
@username = 'user@domain.com'
@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
@lukeholder
Copy link
Copy Markdown

does download path need to be absolute?

@lukeholder
Copy link
Copy Markdown

Found issue... doesn't handle spaces in download path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment