Sunday, January 10, 2010

Automated Backup for Picasa Web Albums

This post describes a script for downloading all the photos in a Picasa Web account. My script is mainly intended for Linux users, because Windows and Mac users can use the Picasa desktop software to download Web albums easily.

Usage
The script is written in Ruby, and uses RubyGems. You will need to install the appropriate packages for your distribution. For example, in Debian and Ubuntu:
sudo apt-get install ruby rubygems libopenssl-ruby

The script uses Google's gdata RubyGem, so you need to install it:
sudo gem install gdata

Download and unpack the script from my GitHub gist. Create an account.yml file in the same folder, using the following template:
username: costan
password: "my secret password"

Run the script:
ruby picasa_downloader.rb

Find your photos, nicely grouped by album, in the picasa_username folder.

For Developers
I used Google's gdata RubyGem, and the Picasa Web Albums protocol guide and protocol reference.

The code is pretty straight-forward. There is one subtlety: for photos bigger than 1600x1200, the Web Albums API returns the URL for 1600x1200 thumbnails by default. To get the original uploaded file, I use the imgmax=d parameter in album feed URIs.

Motivation and Conclusion
I wrote this script because the Picasa desktop software does not seem to be able to download from Picasa Web Albums on Linux.

I hope you found my post useful. I welcome your comments, as well as your pull requests on GitHub.

7 comments:

  1. AnonymousMar 9, 2010 09:31 AM
    Hi, nice script but i am getting these errors (installed on ubuntu the way described)

    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- net/https (LoadError)
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /var/lib/gems/1.8/gems/gdata-1.1.1/lib/gdata/http/default_service.rb:16
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /var/lib/gems/1.8/gems/gdata-1.1.1/lib/gdata/http.rb:15
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /var/lib/gems/1.8/gems/gdata-1.1.1/lib/gdata.rb:17
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from picasa_download.rb:14


    Any hints ?
    ReplyDelete
  2. AnonymousMar 9, 2010 09:34 AM
    `gem_original_require': no such file to load -- net/https (LoadError)

    sudo apt-get install libopenssl-ruby

    worked and solved it... my bad!

    Nice work!!
    ReplyDelete
  3. Victor CostanMar 9, 2010 11:18 AM
    @Anonymous: I saw your comment on my way to work, and was just about to post the same workaround :)

    Thanks so much for noticing and bringing it up! I'm updating the blog post now.
    ReplyDelete
  4. AnonymousMar 9, 2010 01:39 PM
    No worries! I wrote the comment before even googling the error.
    It is working great right now, thanks again for the script!
    ReplyDelete
  5. JindruDec 25, 2010 11:55 AM
    hello. Thanks for your script. I have to report one problem:
    I have 2 albums with the same name ( I don't know, if it's normal/ possible, but it is :-)

    when script try download the second same name album, it crash with:
    picasa_download.rb:71:in `mkdir': File exists - charlie (Errno::EEXIST)
    from picasa_download.rb:71
    from picasa_download.rb:70:in `each'
    from picasa_download.rb:70

    I have to rename the album, but script may rename ( name(2) name(3) or something ) duplicated web album and continue his best work :-)

    thanks

    Jindru
    ReplyDelete
  6. ThomasJul 7, 2011 03:02 PM
    Finally "Pay Dirt!"
    Thanks, this is exactly what I needed!
    :-))
    ReplyDelete
  7. tomaszfNov 11, 2011 07:06 AM
    Works fine, good work! I even managed to download albums belonging to other user by changing path in script.
    There's problem when album name contains chars which are not permitted in folder name (like "/"). Simple string replace solved my problem.
    ReplyDelete