Skip to content

Instantly share code, notes, and snippets.

@kalbasit
Forked from maca/das_download.rb
Created February 27, 2012 23:37
Show Gist options
  • Save kalbasit/1927927 to your computer and use it in GitHub Desktop.
Save kalbasit/1927927 to your computer and use it in GitHub Desktop.
Script to download all Destroy All Software screencasts, account needed
#! /usr/bin/env ruby
# usage:
# $ das_download.rb email password [download_directory]
require 'mechanize'
# gem 'mechanize-progressbar'
email = ARGV[0] or raise('Please provide the email address for your account')
password = ARGV[1] or raise('Please provide the password for your account')
path = (ARGV[2] || './').gsub /\//,''
download = lambda do |url, file|
agent = Mechanize.new
agent.get 'https://www.destroyallsoftware.com/screencasts/users/sign_in'
form = agent.page.forms.first
form['user[email]'] = email
form['user[password]'] = password
form.submit
agent.pluggable_parser.default = Mechanize::Download
agent.get(url).save(file)
end
agent = Mechanize.new
agent.get 'https://www.destroyallsoftware.com/screencasts/catalog'
screencasts = agent.page.search('li.screencast').reverse
screencasts.each_with_index do |screencast, index|
title = screencast.search('a').first.text
to_go = "#{screencasts.size - index} to go"
url = screencast.search('.download_link > a:first-child').first['href']
file = "#{path}/#{"%04d" % (index + 1)}-#{title.gsub(/\.|:|,/, '').gsub(/\/|\s/, '-').downcase}.mov"
if File.exists? file
puts "Skipping #{title} - #{to_go}"
else
puts "Downloading #{title} - #{to_go}"
download[url, file]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment