Created
September 3, 2012 13:40
-
-
Save brymck/3609400 to your computer and use it in GitHub Desktop.
Download all photos from a set in Flickr
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 | |
# To get a list of available albums: | |
# flickr_set.rb bryanmckelvey | |
# | |
# To download an album: | |
# flickr_set.rb bryanmckelvey "Fall 2011" | |
require "fleakr" | |
# Get an API key at http://www.flickr.com/services/apps/create/apply | |
Fleakr.api_key = "YOURAPIKEYHERE" | |
# Delete any of these you don't want | |
VALID_SIZES = [:original, :large, :medium, :small, :thumbnail, :square] | |
user_name, set_name = ARGV | |
count = 0 | |
if user_name.nil? | |
puts "Please supply a user name" | |
exit 1 | |
end | |
user = Fleakr.user(user_name) | |
if user.nil? | |
puts "Could not find user: #{user_name}" | |
exit 1 | |
end | |
if set_name.nil? | |
puts "Available sets:" | |
user.sets.each do |set| | |
puts "%-18s %s" % [set.id, set.title] | |
end | |
exit 0 | |
end | |
set = user.sets.find { |s| s.title == set_name || s.id == set_name } | |
if set.nil? | |
puts "Could not find set: #{set_name}" | |
exit 1 | |
end | |
set.photos.each do |photo| | |
best_size = VALID_SIZES.find { |s| !photo.send(s).nil? } | |
if best_size.nil? | |
puts "Could not find adequate size for photo of title: #{photo.title}" | |
else | |
size = photo.send(best_size) | |
puts "Saving %s.jpg (%s: %d x %d)" % [photo.id, best_size, size.width, size.height] | |
count += 1 | |
size.save_to "#{photo.id}.jpg" | |
end | |
end | |
puts "(#{count} photo#{count == 1 ? "" : "s"} saved)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment