Philipp91 / picasa2digikam

Script to migrate Picasa metadata to digiKam
GNU General Public License v3.0
18 stars 3 forks source link

picasa2digikam

A script to migrate Picasa metadata from its .picasa.ini files and/or contacts.xml file to the digiKam database.

It does not require Picasa to be installed and therefore does not require Windows.

It does not write into the original Picasa file system, so the original files should remain untouched.

Supported metadata

Where to find contacts.xml?

Installation

Clone the repository and cd into it. Make sure you have Python 3.10 or newer installed. Install pip3 install psutil. On Windows, also pip3 install pywin32.

Suggested usage

This script writes into the digiKam database. If you already have photos in digiKam, you should at least make a backup. Furthermore, testing shows this script works best when writing into an "empty" digiKam instance. If you already have faces identified prior to running this script, you might get duplicate entries if the digiKam name does not match the name this script found.

You may also want to make a backup of the photo directories, though the script doesn't write there. Depending on your metadata sync settings in digiKam, digiKam itself may (or not) write some of the added metadata to EXIF tags in your photos.

  1. Optional: As this is your last chance to make edits in Picasa that will also be reflected in digiKam, you may want to do some cleanups there:
    • Delete unnecessary albums and tags.
    • Go over the detected faces in the "Unknown" folder, as well as the suggestions.
  2. Open digiKam. If it shows a first-start wizard, do NOT add your photos yet (there's a bug/feature that makes it not determine every image's size then, but this script needs the sizes).
  3. Make sure you're using an SQLite database (menu "Settings -> Configure digiKam -> Database") and note its path.
  4. Add your photo directory under "Root Album Folders" (menu "Settings -> Configure digiKam -> Collections"). If you have multiple, you must repeat this and the following steps for each root directory separately.
  5. Wait for the "Find new items" job to complete (see progress bar at the bottom, wait until it says "No active process" there). You should now see all your photos in digiKam already, but without their stars and tags.
  6. Execute a dry run. Under Linux, it might look sth like this:
    ./main.py --dry_run \
       --photos_dir='/home/user/Pictures' \
       --digikam_db='/home/user/snap/digikam/common/digikam4.db' \
       --contacts='/mnt/WinDrive/Users/user/AppData/Local/Google/Picasa2/contacts/contacts.xml'

    And when using the Windows Command Prompt (cmd), it might look like this:

    python main.py --dry_run ^
       --photos_dir="C:\Users\user\Pictures" ^
       --digikam_db="C:\Users\user\Pictures\digikam4.db" ^
       --contacts="%LocalAppData%\Google\Picasa2\contacts\contacts.xml"

    In this command, --photos_dir must point to the same directory you configured in step 3 above, or a sub-directory thereof, and --digikam_db must point to the digikam4.db file under the directory configured in step 2 above.
    --contacts is optional but highly recommended.

  7. Make sure there were no errors, and take a look at relevant-looking warnings. Debug if necessary. Sometimes the .ini file is corrupted (probably due to Picasa crashing in the middle of updating an .ini file) -- you will need to edit the .ini file in such cases)
  8. Close digiKam (to prevent concurrent access to the database).
  9. Execute the same command without --dry_run to carry out the migration.
  10. Open digiKam again and do some spot checks to make sure the migration worked as intended. Note: digiKam may have already detected faces during the initial library scan -- in this case you may end up with overlapping face rectangles. If this migration started from a "clean" digiKam, you can just move all the "Unknown" faces to "Ignore", otherwise it may take some time to manually clean up from within digiKam (or by editing digikam4.db using an SQL client).
  11. If you want, you can now run digiKam's face detection to detect faces that Picasa hadn't detected or that were still in the "Unknown" folder in Picasa.

Operation Details

The script writes to the digikam4.db file and creates a backup. However it is also recommended you make a backup too.

contacts.xml usually contains more accurate name information, so locate and provide the file path to it if possible.

In large old collections, there may be some inconsistencies between .ini files due to crashes in Picasa, manual moving, etc. A lot of inconsistencies can be resolved by using the contacts.xml file. If no contacts.xml is available, this script tries to work around some of these issues. For example: