Created
February 8, 2012 23:17
-
-
Save isaacbowen/1775318 to your computer and use it in GitHub Desktop.
Desktopography 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 | |
# desktopography-dl.rb | |
# Requires: nokogiri | |
# | |
# Downloads /everything/ from a given Desktopography exhibition. Assumes we're on | |
# something unixy, with mkdir and wget available for use. | |
require 'open-uri' | |
require 'nokogiri' | |
# pull down list of exhibitions | |
exhibitions_doc = Nokogiri::HTML(open 'http://www.desktopography.net/') | |
exhibitions = Hash[exhibitions_doc.css('#exhibitions .exhibition').map { |e| [e.text.strip.to_i, e['href']] }] | |
# which one, which one... | |
print "Exhibition year? (#{exhibitions.keys.join(', ')})\n> " | |
year = gets.strip.to_i | |
# grab wallpaper list for this exhibition | |
wallpapers_doc = Nokogiri::HTML(open "http://www.desktopography.net#{exhibitions[year]}") | |
wallpapers = wallpapers_doc.css('#wallpapers .wallpaper') | |
puts "#{wallpapers.count} wallpapers found." | |
# for each wallpaper... | |
wallpapers.each do |wallpaper| | |
# requisite info | |
wallpaper_doc = Nokogiri::HTML(open "http://www.desktopography.net/#{wallpaper['href']}") | |
# name appropriately | |
name = wallpaper_doc.css('#title').text.gsub(/[^\w]/, '_').gsub(/(^_+|_+$)/, '') + '.jpg' | |
# download each resolution - stored in Desktopography/:year/:ratio/:resolution/:name.jpg | |
wallpaper_doc.css('.download select option').each do |option| | |
path = ['Desktopography', year, option.parent['label'], option.text, name].join('/') | |
# skip if possible | |
if File.exists? path | |
puts "#{path} exists - skipping..." | |
next | |
end | |
# proceed | |
puts "Downloading #{path}..." | |
`mkdir -p "#{File.dirname path}"` | |
`wget -O "#{path}" "http://www.desktopography.net/#{option['value']}"` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment