Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created August 30, 2010 17:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ELLIOTTCABLE/557750 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/557750 to your computer and use it in GitHub Desktop.
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