Created
March 5, 2012 23:59
-
-
Save h0rs3r4dish/1982250 to your computer and use it in GitHub Desktop.
Download imgur albums all at once
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
#!/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