Skip to content

Instantly share code, notes, and snippets.

@amree
Created April 6, 2018 14:05
Show Gist options
  • Save amree/9200e932b1c6bff1618582db45daa9c1 to your computer and use it in GitHub Desktop.
Save amree/9200e932b1c6bff1618582db45daa9c1 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# usage:
# $ das_download.rb
require "mechanize"
require "fileutils"
class DasDownloader
attr_reader :agent, :email, :password
def initialize
@agent = Mechanize.new
end
def screencasts
screencasts = []
screencasts_metadata_html.each do |html|
next unless (meta = html.at("h1.season_title"))
season = meta.at("img").attr("alt")
html.search(".episode").each do |episode|
title = episode.at(".title").text.gsub("/", "-")
url = episode.at("a").attr("href")
download_url = url + "/download"
description = episode.at(".subtitle").text
duration = episode.at(".duration").text
screencasts << Screencast.new(season, title, description, duration, download_url)
end
end
screencasts
end
def run
screencasts.each do |screencast|
download screencast
end
end
private
def download(screencast)
puts "Downloading #{screencast.season} - #{screencast.title}"
FileUtils::mkdir_p(screencast.season)
Dir.chdir(screencast.season) do
FileUtils::mkdir_p(screencast.title)
Dir.chdir(screencast.title) do
File.open("metadata.txt", "w") do |metadata|
metadata.puts "Title: #{screencast.title}"
metadata.puts "Description: #{screencast.description}"
metadata.puts "Duration: #{screencast.duration}"
end
agent.get("https://destroyallsoftware.com#{screencast.url}").save("screencast.mov")
end
end
end
def screencasts_metadata_html
agent.get "https://www.destroyallsoftware.com/screencasts/catalog"
agent.page.search(".season").reverse
end
Screencast = Struct.new(:season, :title, :description, :duration, :url)
end
DasDownloader.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment