Last active
April 8, 2018 01:47
-
-
Save hannestyden/ecdc061d82c2b89116dc2ee5059a26d5 to your computer and use it in GitHub Desktop.
Destroy All Software downloader
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 | |
# | |
# 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 |
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
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