Skip to content

Instantly share code, notes, and snippets.

@gertig
Forked from jmazzi/peepcode.rb
Created August 18, 2011 20:40

Revisions

  1. Justin Mazzi revised this gist May 25, 2011. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions peepcode.rb
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,14 @@
    require 'mechanize'

    # Downloads everything from the East location.
    # Skips all .ogg files (I don't use them)

    @username = 'user@domain.com'
    @password = 'hi2u'
    @download_path = '/Users/username/peepcode/downloads'
    @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')
    @@ -31,7 +34,7 @@ def wget(path)
    system cmd
    end

    system "cd #{@download_path}; wget --load-cookies ../wget-cookies.txt -c '#{path}'"
    system "cd #{@download_path}; wget --load-cookies #{@wget_cookie} --continue '#{path}'"
    end

    page = agent.get 'https://peepcode.com/products'
    @@ -43,8 +46,9 @@ def wget(path)
    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)
    if !s3 && !ogg && !links.include?(dl.href) && !wmv
    links.push dl.href
    wget dl.href
    end
  2. Justin Mazzi revised this gist May 24, 2011. No changes.
  3. Justin Mazzi revised this gist May 24, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion peepcode.rb
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ def wget(path)
    system cmd
    end

    system "cd #{@download_path}; wget --load-cookies ../wget-cookies.txt '#{path}'"
    system "cd #{@download_path}; wget --load-cookies ../wget-cookies.txt -c '#{path}'"
    end

    page = agent.get 'https://peepcode.com/products'
  4. Justin Mazzi revised this gist May 24, 2011. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions peepcode.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    require 'mechanize'

    # Downloads everything from the East location.
    # Skips all .ogg files (I don't use them)

    @username = 'user@domain.com'
    @password = 'hi2u'
    @download_path = '/Users/username/peepcode/downloads'
  5. Justin Mazzi revised this gist May 24, 2011. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion peepcode.rb
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,10 @@ def wget(path)
    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)
    ogg = dl.href.match(/\.ogg/)
    s3 = (dl.text.match(/USA-West/) || dl.href.match(/s3=true/))

    if !s3 && !ogg && !links.include?(dl.href)
    links.push dl.href
    wget dl.href
    end
  6. Justin Mazzi revised this gist May 24, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion peepcode.rb
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,9 @@

    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"
    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-cookies.txt '#{path}'"
  7. Justin Mazzi created this gist May 24, 2011.
    45 changes: 45 additions & 0 deletions peepcode.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    require 'mechanize'

    @username = 'user@domain.com'
    @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