Created
December 6, 2012 16:38
-
-
Save weppos/4225872 to your computer and use it in GitHub Desktop.
Script to download a Flickr photoset.
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 -wKU | |
require 'rubygems' | |
require 'flickraw' | |
require 'open-uri' | |
require 'fileutils' | |
FlickRaw.api_key = "YOUR_API_KEY" | |
FlickRaw.shared_secret = "YOUR_SHARED_SECRET" | |
photoset = ARGV.first || raise(ArgumentError, "Missing photoset") | |
photos = flickr.photosets.getPhotos(:photoset_id => photoset).photo | |
total_count = photos.size | |
photo_count = 0 | |
FileUtils.mkpath(photoset) | |
photos.each do |photo| | |
photo_count += 1 | |
puts "=> Photo #{photo_count}/#{total_count}" | |
puts " #{photo.id} #{photo.title}" | |
puts " Getting info" | |
info = flickr.photos.getInfo(:photo_id => photo.id, :secret => photo.secret) | |
url = FlickRaw.url_o(info) | |
name = File.basename(url) | |
next if File.exist?("#{photoset}/#{name}") | |
puts " Downloading #{url}" | |
File.open("#{photoset}/#{name}", "wb+") { |f| f.write(open(url).read) } | |
puts " Saved #{photoset}/#{name}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!