Skip to content

Instantly share code, notes, and snippets.

@hannestyden
Forked from jaredculp/das_download.rb
Last active April 8, 2018 01:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hannestyden/ecdc061d82c2b89116dc2ee5059a26d5 to your computer and use it in GitHub Desktop.
Save hannestyden/ecdc061d82c2b89116dc2ee5059a26d5 to your computer and use it in GitHub Desktop.
Destroy All Software downloader
#! /usr/bin/env ruby
#
# Original: https://gist.github.com/maca/1798070
#
# 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_with_index do |episode, index|
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(index + 1, 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.index} - #{screencast.title}"
FileUtils::mkdir_p(screencast.season)
Dir.chdir(screencast.season) do
o_dir = screencast.title
dir = "#{screencast.index} - " + screencast.title
FileUtils::mv(o_dir, dir)
# FileUtils::mkdir_p(dir)
Dir.chdir(dir) do
# File.open("metadata.txt", "w") do |metadata|
# metadata.puts "Title: #{screencast.title}"
# metadata.puts "Description: #{screencast.description}"
# metadata.puts "Duration: #{screencast.duration}"
# metadata.puts("Location: https://destroyallsoftware.com#{screencast.url}")
# 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(:index, :season, :title, :description, :duration, :url)
end
DasDownloader.new.run
source 'https://rubygems.org' do
gem 'mechanize'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment