Tags resurrection.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Tags resurrection.

vlapekng
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 ----------------------


_______________________________________________
Digikam-users mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-users
Reply | Threaded
Open this post in threaded view
|

Re: Tags resurrection.

pshute
But did you work out how it happened? That information, and your good work below could be very useful to a few people.

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> Sent: Saturday, 8 January 2011 6:17 AM
> To: [hidden email]
> Subject: [Digikam-users] Tags resurrection.
>
> 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 ----------------------
>
>
> _______________________________________________
> Digikam-users mailing list
> [hidden email]
> https://mail.kde.org/mailman/listinfo/digikam-users
>
_______________________________________________
Digikam-users mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-users
Reply | Threaded
Open this post in threaded view
|

Re: Tags resurrection.

Kyle Altendorf
In reply to this post by vlapekng
On Fri, Jan 7, 2011 at 14:17,  <[hidden email]> wrote:
> 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

I'm reading between the lines here...  but it seems that maybe your
image files moved to a different path?  More specifically, the
collection path changed?  Does digiKam provide a method to record this
after the fact?  If so, it is not apparent in the collections dialog.

Cheers,
-kyle
_______________________________________________
Digikam-users mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-users
Reply | Threaded
Open this post in threaded view
|

Re: Tags resurrection.

Peter Gervai-2
Kyle Altendorf <kyle.altendorf@...> writes:

> On Fri, Jan 7, 2011 at 14:17,  <vlapekng@...> wrote:
> > 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
>
> I'm reading between the lines here...  but it seems that maybe your
> image files moved to a different path?  More specifically, the
> collection path changed?  Does digiKam provide a method to record this
> after the fact?  If so, it is not apparent in the collections dialog.

This is not a direct reply, but may help some.

I move my images a lot, since it's wandering from the current
directory to the "wait for dvd" dir, then the "archives", and
these are all different places, different albums. I started to
clean up the dupes and realised that tags got dumped. I wasn't
happy.

Anyway I realised that the db has the info, just it's too stupid to
realise that the same bloody hash _have_to_be_ the same file, no
matter where. But okay, MAYBE there is a situation when someone wants
to have the SAME image with DIFFERENT tags, I guess. (Sounds quite
insane to me, but...)

So I wrote a small program which distributes tags to the images with
the same hash, no matter what album or path.

The program was slightly tested (on my db, that's it), seems to be
okay but I'm sleepy enough not to prove its correctness ;-) so
please make backups and check afterwards.

http://foobar.grin.hu/digikam/digikam_tag_distributor.pl

Hope it helps.

But it would be much better if digikam would be smart enough to
see that UNIQUE hash should be indeed unique so it is the same
image so the tags could be as well (or at least offer a switch
to behave like that). Paths are obsolete when using unique hashes
anyway. ;-)

I moved over from F-Spot, and I'm mostly okay. (I painfully miss the
timeline of F-Spot because Digikam's is a piece of crap.)
Slow startup time and the obligatory crash at exit is not that bad. :-]

byte-byte,
  grin


_______________________________________________
Digikam-users mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-users