Skip to content

Instantly share code, notes, and snippets.

@jasondew
Forked from maca/das_download.rb
Last active October 25, 2024 12:38
Show Gist options
  • Save jasondew/5583811 to your computer and use it in GitHub Desktop.
Save jasondew/5583811 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# usage:
# $ das_download.rb email password [download_directory]
require "mechanize"
class DasDownloader
attr_reader :agent, :email, :password
def initialize(email, password)
@agent = Mechanize.new
@email, @password = email, password
end
def screencasts
screencasts_metadata_html.map do |html|
next unless (meta = html.at(".title a"))
title = meta.text
url = meta.attr("href")
download_url = url + "/download"
description = agent.get(url).at(".details p").text.strip
category = html.at(".category").text
duration = html.at(".duration").text
Screencast.new title, category, duration, description, download_url
end
end
def run
screencasts.each do |screencast|
download screencast
end
end
private
def login
agent.get "https://www.destroyallsoftware.com/screencasts/users/sign_in"
if (form = agent.page.forms.first)
form["user[email]"] = email
form["user[password]"] = password
form.submit
agent.pluggable_parser.default = Mechanize::Download
end
end
def download(screencast)
puts "Downloading #{screencast.title}"
login
Dir.mkdir(screencast.title)
Dir.chdir(screencast.title) do
File.open("metadata.txt", "w") do |metadata|
metadata.puts "Title: #{screencast.title}"
metadata.puts "Category: #{screencast.category}"
metadata.puts "Duration: #{screencast.duration}"
metadata.puts "Description: #{screencast.description}"
end
agent.get(screencast.url).save("screencast.mov")
end
end
def screencasts_metadata_html
login
agent.get "https://www.destroyallsoftware.com/screencasts/catalog"
agent.page.search(".screencast").reverse
end
Screencast = Struct.new(:title, :category, :duration, :description, :url)
end
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")
DasDownloader.new(email, password).run
@jaredculp
Copy link

@gudnm @dprandzioch I've forked this and updated it to work with the latest since DAS is free this week: https://gist.github.com/jaredculp/f26f83d214cf926472dddd4269bd2538

@elo-siema
Copy link

@jaredculp
Changed it a bit to work on Windows by replacing forbidden characters in filenames:
https://gist.github.com/elochim-siemasz/64edda44c2fcfc28d6b7eed9f78cd62c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment