From 8f7fff43e5f89d78f36129cc35c070f6a9759caa Mon Sep 17 00:00:00 2001 From: Guillaume Castagnino Date: Wed, 11 Mar 2020 00:05:25 +0100 Subject: [PATCH] shotwell migrate to xmp for digikam import --- migrate_shotwell.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 migrate_shotwell.py diff --git a/migrate_shotwell.py b/migrate_shotwell.py new file mode 100755 index 0000000..a56c4ba --- /dev/null +++ b/migrate_shotwell.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +import os +import sqlite3 + +shotwell = sqlite3.connect(os.getenv('HOME', '.') + '/.local/share/shotwell/data/photo.db') +shotwell.row_factory = sqlite3.Row + +for c in shotwell.execute('SELECT id, rating, filename FROM PhotoTable p'): + report = "thumb%0.16x\t" % c['id'] + report += "%d\t%d\t" % ( c['id'], c['rating'] ) + tags = [t['name'] for t in [tag for tag in shotwell.execute('SELECT name FROM TagTable WHERE photo_id_list LIKE ?', ('%%thumb%0.16x%%' % c['id'], ))]] + report += ",".join(tags) + report += "\t%s" % c['filename'] + if len(tags) > 0: + #print(report) + # create exiv2 cmp file + cmd_file = c['filename'] + '.cmd' + f = open(cmd_file, "a") + for t in tags: + print("set Xmp.dc.subject XmpBag %s" % (t), file = f) + print("set Xmp.digiKam.TagsList %s" % (t), file = f) + f.close() + # create xmp sidecar + command = u'''exiv2 -eX -m "%s" "%s"''' % (cmd_file, c['filename']) + print(command) + good_sidecar = c['filename'] + '.xmp' + bad_sidecar = c['filename'][:-4] + '.xmp' + ret = os.system(command.encode('utf-8')) + if ret != 0: + print("warning: exiv command return %d, ran: %s" % (ret, command)) + else: + os.rename(bad_sidecar, good_sidecar) + os.remove(cmd_file)