|
#!/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 () |