Tuesday, December 27, 2011

Importing photos from F-Spot in Picasa

Gnome users know F-spot, a photo management software for Gnome.
I used to use F-Spot for a while and my photo library of almost 13 000 photos is organized with the following directories: Year/Month/Day.
Importing all of this into Picasa could be as simple configuring Picasa to watch the old F-Spot photos directory.
However, I wanted my photo library to fit Picasa's naming conventions which is one directory named Year-Month-Day and all the photos of that day inside.

What follows is the code of a small Python script I wrote to do the job.

How to use the script?

 - Copy paste the code in a file named convert2picasa.py;
 - Put this file at the root of your old photo library;
 - Make the file executable with chmod +x convert2picasa.py.

Run it in a terminal.
Once finished, you will notice a new directory named Picasa in your old photo library. This is where all of your photos have been copied following the Picasa naming convention. Therefore you can now simply cut and paste its content in your Picasa library directory!


#!/usr/bin/env python

import os
import shutil

print 'Creating picasa output directory...'
except OSError:

print 'Copying your Year/Month/Day organized photo library to a Year-Month-Day organized library into the picasa directory...'
for dirname, dirnames, filename in os.walk('.'):
    dir_components = dirname.split('/')[1:]
    if len(dir_components) == 3:
        dest_dirname = '-'.join(dir_components)
        dest_dirname = "./picasa/{0}".format(dest_dirname)
        except OSError:
            print "Processing {0}...".format(dest_dirname)
            for f in filename:
                source_file = "{0}/{1}".format(dirname, f)
                dest_file = "{0}/{1}".format(dest_dirname, f)
                print "Copying {0} to {1}...".format(source_file, dest_file)
                shutil.copy2(source_file, dest_file)