Skip to content

Instantly share code, notes, and snippets.

@jeremyjs
Forked from ckahle33/das.rb
Last active April 10, 2018 20:04
Show Gist options
  • Save jeremyjs/5d4cb855228ce24df9f5ac329539c4fc to your computer and use it in GitHub Desktop.
Save jeremyjs/5d4cb855228ce24df9f5ac329539c4fc to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# requirements:
# gem install mechanize
#
# usage:
# das_download.rb [download_directory]
require 'mechanize'
path = ARGV[0] || './'
download = lambda do |url, file|
agent = Mechanize.new
agent.pluggable_parser.default = Mechanize::Download
agent.get(url).save(file)
end
root = 'https://www.destroyallsoftware.com'
agent = Mechanize.new
agent.get("#{root}/screencasts/catalog")
screencasts = agent.page.search('div.episode').reverse
total = screencasts.size
resolution = '4k'
dwnld_slug = "download?resolution=#{resolution}"
index = 0
while screencast = screencasts.pop
index += 1
title = screencast.search('.title').first.text
url = "#{root}/#{screencast.search('a').first['href']}/#{dwnld_slug}"
file = "#{path}/#{'%03d' % index}_#{title.gsub(/\n\.|:|,/, '').gsub(/\/|\s+/, '-').downcase}.mp4"
puts "Downloading\t#{title.ljust(32)}\tas\t#{file.ljust(48)}\t| #{index}/#{total}"
next if File.exist?(file)
download[url, file]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment