Skip to content

Instantly share code, notes, and snippets.

@h0rs3r4dish
Created March 5, 2012 23:59
Show Gist options
  • Save h0rs3r4dish/1982250 to your computer and use it in GitHub Desktop.
Save h0rs3r4dish/1982250 to your computer and use it in GitHub Desktop.
Download imgur albums all at once
#!/usr/bin/env ruby
require "net/http"
if ARGV.length == 0 then
puts "Usage: #{__FILE__.split('/').last} album loc [albumN locN ...]"
exit
end
while ARGV.length > 0
album = ARGV.shift
folder = ARGV.shift || "."
album_url = (album =~ /http/) ? album : "http://imgur.com/a/#{album}"
system("mkdir #{folder}") unless File.directory? folder
list = Net::HTTP.get(URI.parse(album_url)).split("\n").select { |line|
line.scan('<a href="/download/').length > 0
}.map { |line|
line.sub(/^[^"]*"/,'').sub(/".*$/,'')
}
list.each_with_index { |link, i|
puts "#{link.split('/').last} (#{i+1}/#{list.length})"
filename = link.split('/').last + ".jpeg"
data = Net::HTTP.get(URI.parse("http://imgur.com"+link))
File.open(folder+"/"+filename, "w") { |f|
f.puts data
}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment