-
-
Save jasondew/5583811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jaredculp
Changed it a bit to work on Windows by replacing forbidden characters in filenames:
https://gist.github.com/elochim-siemasz/64edda44c2fcfc28d6b7eed9f78cd62c