Skip to content

Instantly share code, notes, and snippets.

@weppos

weppos/fliwn.rb

Created Dec 6, 2012
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@robertokl robertokl commented Apr 18, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.