Saturday 1 March 2008

Ruby Interface for Google Picasa API

A nascent ruby module for interfacing with Picasa and mirroring user albums locally (initially conceived so I could programmatically delete the multitude of galleries I'd spawned while hacking around trying to get stuff to work).

Picasync::Album.find(:all).each {|album|
album.delete!
}

%w(one two three).each do |title|
album = Picasync::Album.new(title)
album.create!
end

Easy. No ability to upload images via the api yet, although its purpose is to farm-out uploading and cms tasks to Picasa's UI anyhow, so that Picasa can essentially power a site's galleries (but without hotlinking or hitting their feed on every page load).

Albums are synced locally via Picasync::Sync::All.new & Picasync::Sync::CSV.new, which fetches files to a single directory, hashing the file names and generating a couple of csvs for image sizes, captions and parent albums. Still to add table migrations and automatic csv imports.

It's also simple to fetch files arbitrarily, be it a whole album, or a particular image in a set (although things aren't properly tied together with csv generation yet):

Picasync::Image.mirror(:album, album.id)
Picasync::Image.mirror(image.id, album.id)

Uses google's ClientLogin authentication scheme.

It's a work in progress and definitely not a drop-in solution for end users, but you can grab (and contribute to) the code on Github.

See the Readme for the methods I've got around to adding.

albums = Picasync::Album.find(:all, :images)
albums.each do |album|
puts album.title
album.images.each {|image|
puts img.medium
puts img.caption
}
end

No comments: