Skip to content

Instantly share code, notes, and snippets.

@nooodl
Created July 13, 2012 16:05
Show Gist options
  • Save nooodl/3105692 to your computer and use it in GitHub Desktop.
Save nooodl/3105692 to your computer and use it in GitHub Desktop.
imgur album downloader
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