diff --git a/metaSave b/metaSave index 2f88e16..cc56a69 100755 --- a/metaSave +++ b/metaSave @@ -25,8 +25,9 @@ import os import re import sys import fnmatch +import traceback from picasa3meta import thumbindex, pmpinfo, iniinfo, exiv2meta, contacts - +from codecs import open def locatedir(pattern,start): @@ -124,7 +125,7 @@ def main(): "photo tree and Picasa3 files to another system or have them "\ "remotely mounted with a different path you can use --tweak to "\ "adjust the path. \nexample:\n\t"\ - "--tweak '/my/path/Pictures':'/thumbindex/path/Pictures'" ) + "--tweak '/my/path/Pictures'::'/thumbindex/path/Pictures'" ) args = parser.parse_args() @@ -155,7 +156,7 @@ def main(): os.path.join(args.dest,os.path.basename(source)+".meta")) if args.tweak != "": - myPath, thumbPath = args.tweak.split(':') + myPath, thumbPath = args.tweak.split('::') # double colon for windows compatability (C:\bla split otherwise) else: myPath = "" thumbPath = "" @@ -228,6 +229,7 @@ def main(): iniDir = os.path.dirname(img) if myPath != "": pmpDir = iniDir.replace(myPath,thumbPath) + else: pmpDir = iniDir outDir = iniDir.replace(source,dest) outBase = os.path.basename(img) outFile = os.path.join(outDir,outBase+".meta") @@ -237,10 +239,10 @@ def main(): except: pass - oF = open(outFile,"w") + oF = open(outFile,"w", "utf-8") # pmp index index = picasaDb.indexOfFile(os.path.join(pmpDir,outBase)) - oF.write("pmp.index:%d\n"%index) + oF.write("pmp.index:%d\n"%index) # pmp info for K,V in pmpDB.getEntry(index): oF.write("pmp.%s:%s\n"%(K,V)) @@ -300,12 +302,16 @@ def main(): # and finally, exiv2 data for K,V in exiv2meta.EXIV2Meta(img): + V = V or "" # replace NoneType with empty string (avoid NoneType error) + if not isinstance(V, str): + V=", ".join(V) # join lists (like face data) + V = V.encode('string_escape') # escape invalid bytes oF.write("%s:%s\n"%(K,V)) oF.close() print "%d files"%count except: - print "error: ",sys.exc_info()[0],":",sys.exc_info()[1] + traceback.print_exc(file=sys.stdout) # print a full stack trace return 3 if __name__ == "__main__":