[Digikam-users] Tags resurrection.

vlapekng at vpek.info vlapekng at vpek.info
Fri Jan 7 19:17:24 GMT 2011


Hi,
Last time I clean-up my home folder and after starting Digikam my albums 
disappear. Five years of tagging, heeeee ???!!! (Not so bad. Of course I 
have backup. But it is to simple to restore it. Better is find the way how 
to rescue something - remember: .... "because linux IS the game" )
When I recreate albums all tags assigned to photos went (of course).

Non programmers skip this section.
So After closer look, in Digikam database all images was twice. Old images 
without filled album, but asserted tags and 'new' images with filled album 
column but without tags assigned. So I was happy, quite no problem.

For lamas:
This script assign old tags if the image file name remain, but folder/album 
change. 
0, All tags went.
1, Create new collections (in Digikam) from the "new/old" image directory. 
Digikam database must remain !
3, Run script (it is in python). Or manualy run SQL in sqlitebrowser.

Issues: 
Duplicate image names: tags are added from all 'old' images with the same 
name. (It is better to have some twice, that miss something, so?)


Script ( also on http://pastebin.com/UcrL8ydu )
#--------------- Cut here ----------------------
#!/usr/bin/env python

import sqlite3

# go create digikam database backup before continue !!!

#fill full path to digikam database  
conn = sqlite3.connect('/home/.../Pictures/digikam4.db')

c = conn.cursor()
for rate in [0,1,2,3,4,5]:
    print("Assign rate {0}/5".format(rate))
    c.execute("""
    UPDATE ImageInformation set rating = {0}
    WHERE imageid is not -1 and imageid in (
        SELECT i1.id AS new_imageid
	      FROM Images i1,
                   Images i2,
                   Albums a,
                   ImageInformation ii2
              WHERE a.id = i1.album AND
                    i1.name=i2.name AND
                    NOT (i1.id=i2.id) AND
                    ii2.imageid = i2.id AND
                    ii2.rating = {0}
       )""".format(rate))
    conn.commit()
              
print("Assign old tags")
c.execute(""" INSERT into ImageTags
SELECT DISTINCT i1.id AS imageid, it.tagid AS tagid
	      FROM Images i1,
                   Images i2,
                   Albums a,
                   ImageTags it
              WHERE a.id = i1.album AND
                    i1.name=i2.name AND
                    NOT (i1.id=i2.id) AND
                    it.imageid = i2.id
              ORDER BY imageid,tagid
              """)
conn.commit()


c.close()
conn.close()
#--------------- Cut here ----------------------





More information about the Digikam-users mailing list