Skip to content

Instantly share code, notes, and snippets.

@weppos
Created December 6, 2012 16:38
Show Gist options
  • Save weppos/4225872 to your computer and use it in GitHub Desktop.
Save weppos/4225872 to your computer and use it in GitHub Desktop.
Script to download a Flickr photoset.
#!/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
@robertokl
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment