Skip to content

Instantly share code, notes, and snippets.

@serdary
Forked from kalbasit/das_download.rb
Last active December 11, 2015 00:59
Show Gist options
  • Save serdary/4520575 to your computer and use it in GitHub Desktop.
Save serdary/4520575 to your computer and use it in GitHub Desktop.
Edited to download ios screencast file too. - Downloads all DAS screencasts, forked from eMxyzptlk
#! /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"
2.times do |file_ind|
css_selector = (file_ind == 0) ? ".download_link > a:first-child" : ".download_link > a:nth-child(2)"
file_postfix = (file_ind == 0) ? "" : "_ios"
url = screencast.search(css_selector).first['href']
file = "#{path}/#{"%04d" % (index + 1)}-#{title.gsub(/\.|:|,/, '').gsub(/\/|\s/, '-').downcase}#{file_postfix}.mov"
if File.exists? file
puts "Skipping #{title} #{[file]} - #{to_go}"
else
puts "Downloading #{title} #{[file]} - #{to_go}"
download[url, file]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment