Created
July 13, 2012 16:05
-
-
Save nooodl/3105692 to your computer and use it in GitHub Desktop.
imgur album 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
require 'nokogiri' | |
require 'open-uri' | |
url = ARGV[0] || gets | |
out = ARGV[1] || url.split('/')[-1] | |
puts "Retrieving album page..." | |
url = "http://imgur.com/a/#{url}" unless url =~ /^http/ | |
doc = Nokogiri::HTML(open(url).read) | |
(imgs = doc.css(".view a")).each_with_index do |u, i| | |
puts "Retrieving images... (#{i + 1}/#{imgs.size})" | |
extension = u["href"].split('.')[-1] | |
filename = "#{out}-#{i + 1}.#{extension}" | |
img = open(u["href"], "rb").read | |
open(filename, "wb").write(img) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment