Created
August 30, 2010 17:46
-
-
Save ELLIOTTCABLE/557750 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'net/http' | |
extensions = %w(jpg png jpeg gif) | |
URLs = Array.new; puts "Gimmie sum urlzorz: (newline to complete)" | |
while (url = STDIN.gets.chomp) =~ %r http:// ; URLs << url; end | |
artist = nil; DERP = Class.new(StandardError) | |
URLs.each do|url| begin raise DERP if artist.nil? | |
d, number = url.match( %r http://(?:www.)?([^/]+)/pic-(\d+).html )[1,2] | |
domain = "pictures.#{d}" | |
Net::HTTP.start(domain, 80) do|http| | |
raise DERP unless path = extensions.map {|ext| "/#{artist[0].downcase}/#{artist}/#{number}.#{ext}" } | |
.detect {|path| http.head(path).code == "200" } | |
`wget "http://#{domain}#{path}"` | |
end | |
rescue DERP | |
`open #{url}`; puts "Please enter the artist name:"; artist = STDIN.gets.chomp | |
artist = $~[1] if artist =~ %r http://(?:www.)?(?:[^/]+)/user-([^\.]+).php | |
retry | |
end end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment