Simple ruby script, for downloading flickr’s photosets
Requirements
sudo gem install flickraw mechanize
Usage
ruby flickr.rb
Code
#!/usr/local/rvm/ruby
# encoding: utf-8
require "fileutils"
require "flickraw"
require "mechanize"
m = Mechanize.new
FlickRaw.api_key = "<YOU_API_KEY>"
FlickRaw.shared_secret = "<YOR_API_SECRET>"
photosets = %w{<PHOTOSTREAM_ID> <PHOTOSTREAM_ID> <PHOTOSTREAM_ID> <PHOTOSTREAM_ID>}
photosets.each do |photoset_id|
list = flickr.photosets.getPhotos(photoset_id: photoset_id, extras: 'url_o, url_l, url_m')
h = list.to_hash
h["photo"].each do |p|
url = p["url_o"] || p["url_l"] || p["url_m"]
filedir = "flickr/#{photoset_id}"
filename = File.basename(url)
filepath = "#{filedir}/#{filename}"
next if File.exists?(filepath)
file = m.get(url)
FileUtils.mkdir_p(filedir)
file.save_as(filepath)
end
end