Skip to content

Instantly share code, notes, and snippets.

@mchung
Created March 25, 2011 01:01
Show Gist options
  • Save mchung/886196 to your computer and use it in GitHub Desktop.
Save mchung/886196 to your computer and use it in GitHub Desktop.
"Dammit, I can't believe Picasa requires me to download photos one by one. Someone needs to do something about that."
#!/usr/bin/env ruby
require "net/http"
require "rexml/document"
class PicasawebDownloadClient
PICASAWEB = "picasaweb.google.com"
# Will return a list of links to every photo in an album
#
# Let's go DOM spelunking.
def find_links_for_album(googleUser, picasaAlbum, authkey = nil)
httpnet = Net::HTTP.new(PICASAWEB, 80)
httpnet.start do |http|
url = "/data/feed/api/user/#{googleUser}/album/#{picasaAlbum}?kind=photo"
url = url + "&authkey=#{authkey}" unless authkey.nil?
request = Net::HTTP::Get.new(url)
response = http.request(request)
response.value
#File.open("xml.data", "w") {|x| x.write response.body }
root = REXML::Document.new(response.body).root
list = root.elements.collect("//entry/media:group/media:content") {|x| x.attributes["url"]}
end
end
end
if __FILE__ == $0
if ARGV.length == 0
puts "Generate curl statements that will download all photos in a Picasa photo album\n\nUsage: #{__FILE__} user album [authkey] | sh"
exit
end
user, album, authkey = ARGV[0], ARGV[1], ARGV[2]
# puts "Downloading #{user}/#{album} (authkey = #{authkey})"
list = PicasawebClient.new.find_links_for_album(user, album, authkey)
list.each {|x| puts "curl -O #{x}"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment