Skip to content

Instantly share code, notes, and snippets.

@jpriebe
Created December 11, 2016 18:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpriebe/df09d23e32640853dee3198b95f5aa3d to your computer and use it in GitHub Desktop.
Save jpriebe/df09d23e32640853dee3198b95f5aa3d to your computer and use it in GitHub Desktop.
Move Picasa 3 tags into EXIF data for an entire library of photos
#!/usr/bin/python
from picasa3meta import pmpinfo
from picasa3meta import thumbindex
import fnmatch
import os
import sys
# python picasa_tags_to_exif.py db_dir root_dir search replace
if len (sys.argv) != 5:
print "\n\nUsage: %s DB_DIR ROOT_DIR SEARCH REPLACE"%(sys.argv[0])
print "\n DB_DIR directory containing the picasa PMP files and the thumbindex.db"
print " ROOT_DIR directory containing the image files"
print " SEARCH pattern to replace with REPLACE in image paths to map filesystem to databases\n\n"
sys.exit(1)
print "reading databases in %s..."%(sys.argv[1])
db = thumbindex.ThumbIndex(sys.argv[1] + "/thumbindex.db")
pmp = pmpinfo.PmpInfo(sys.argv[1], "imagedata")
print "traversing %s; replacing '%s' with '%s'..."%(sys.argv[2],sys.argv[3],sys.argv[4])
f = open ("tags.dat", "a")
matches = []
for root, dirnames, filenames in os.walk(sys.argv[2]):
filtered_filenames = fnmatch.filter(filenames, '*.JPG') + fnmatch.filter(filenames, '*.jpg') + fnmatch.filter(filenames, '*.JPEG') + fnmatch.filter(filenames, '*.jpeg') + fnmatch.filter(filenames, '*.TIF') + fnmatch.filter(filenames, '*.tif') + fnmatch.filter(filenames, '*.TIFF') + fnmatch.filter(filenames, '*.tiff') + fnmatch.filter(filenames, '*.PNG') + fnmatch.filter(filenames, '*.png')
for filename in filtered_filenames:
fullpath = os.path.join(root, filename)
fullpath_mod = fullpath.replace(sys.argv[3], sys.argv[4])
index = db.indexOfFile(fullpath_mod)
for col, val in pmp.getEntry(index):
if 'imagedata_tags' in col and val != '':
f.write ("%s\t%s\n"%(fullpath,val))
cmd = "exiftool "
keywords = val.split(',')
for keyword in keywords:
cmd += "-keywords=\"%s\" "%(keyword)
for keyword in keywords:
cmd += "-XMP:Subject=\"%s\" "%(keyword)
cmd += "\"%s\""%(fullpath)
print cmd
os.popen(cmd)
f.close ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment