Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /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|
number = "%02d" % episode.at(".number").text.to_i
title = episode.at(".title").text.gsub("/", "-")
.gsub(" ", "_")
.downcase
url = episode.at("a").attr("href")
download_url = url + "/download"
screencasts << Screencast.new(season, number, title, 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
agent.get("https://destroyallsoftware.com#{screencast.url}")
.save("#{screencast.number}-#{screencast.title}.mov")
end
end
def screencasts_metadata_html
agent.get "https://www.destroyallsoftware.com/screencasts/catalog"
agent.page.search(".season").reverse
end
Screencast = Struct.new(:season, :number, :title, :url)
end
DasDownloader.new.run
@elo-siema

This comment has been minimized.

Copy link

@elo-siema elo-siema commented Apr 6, 2018

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

@vinitkumar

This comment has been minimized.

Copy link

@vinitkumar vinitkumar commented Apr 6, 2018

@elochim-siemasz Does it still works for you?

@Omar-Elrefaei

This comment has been minimized.

Copy link

@Omar-Elrefaei Omar-Elrefaei commented Apr 9, 2018

O $h*t this worked perfectly !!!
Thanks so much ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.