-
-
Save matiskay/8137957 to your computer and use it in GitHub Desktop.
This file contains 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
require 'mechanize' | |
@username = 'USERNAME' | |
@password = 'PASSWORD' | |
@download_path = File.expand_path '~/videos' | |
@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/orders' | |
page.links_with(:href => %r{/orders/}).each do |link| | |
puts "Processing #{link.text}" | |
result = agent.click link | |
links = [] | |
download_links = result.links_with(:href => %r{/downloads/}).each do |dl| | |
#ogg = dl.href.match(/\.ogg/) | |
#s3 = (dl.text.match(/USA-West/) || dl.href.match(/s3=true/)) | |
mov = false | |
mov = dl.href.match(/.mov_z$/) | |
if mov | |
links.push dl.href | |
puts "Downloading #{dl.href}" | |
wget dl.href | |
end | |
#if !s3 && !ogg && !links.include?(dl.href) && !wmv | |
# links.push dl.href | |
#end | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment