#!/usr/bin/ruby # # Copyright (c) 2007 Daniel Rodríguez Troitiño # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Use: # 1. Search for the "RSS" link in the Picasa Web Album you want. You can find # it at the bottom of the album picture index. # 2. Move to the directory you want your photos to be downloaded. # 3. Use the RSS link URL from the first step as the second argument for # baja-fotos.rb. # 4. Enjoy. require 'open-uri' require 'rss' require 'open-uri' require 'pathname' require 'fileutils' if ARGV.length == 0 puts "Use: baja-fotos.rb [RSS URL]" exit 0 end rss_url = ARGV[0] puts "Downloading photos from <#{rss_url}>" rss_file = open(rss_url) rss = RSS::Parser.parse(rss_file) num_items = rss.items.length puts "Total photos: #{num_items}" rss.items.each_with_index do |item, index| enclosure_url = URI.parse(item.enclosure.url) file_path = Pathname.new(enclosure_url.path) local_file_name = URI.unescape(file_path.basename.to_s) puts "Photo #{index+1} of #{num_items} -> #{local_file_name}" enclosure = open(enclosure_url.to_s) FileUtils.copy(enclosure.path, local_file_name) enclosure.close end