ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: StarGeek on May 03, 2017, 03:32:08 PM

Title: Problem with Shortcuts and NoDups(1)
Post by: StarGeek on May 03, 2017, 03:32:08 PM
I'm trying out the NoDups utility and something doesn't seem right under windows with NoDups(1) and shortcuts.

I have a shortcut for Keywords and Subject defined
MyKeywords => ['XMP-dc:Subject','IPTC:Keywords'],
and I was thinking I could get rid of my current user-defined tag that combines and removes duplicates for Subject and Keywords by using this
-sep "##" "-MyKeywords<${MyKeywords;NoDups(1)}"

The docs say that NoDups(1) is supposed to return undef if no duplicates exist but that doesn't seem to be the case.
C:\>exiftool -MyKeywords X:\!temp\Test3.jpg
Subject                         : A, B
Keywords                        : C, D

C:\>exiftool -sep "##" -if "defined ${MyKeywords;NoDups(1)}" -p "MyKeywords-> ${MyKeywords;NoDups(1)}" X:\!temp\Test3.jpg
MyKeywords->

C:\>exiftool -sep "##" "-MyKeywords<${MyKeywords;NoDups(1)}" X:\!temp\Test3.jpg
    1 image files updated

C:\>exiftool -MyKeywords X:\!temp\Test3.jpg
Subject                         :
Keywords                        :


Removing the (1) option works like this, which seems correct to me.
C:\>exiftool -MyKeywords X:\!temp\Test3.jpg
Subject                         : A, B
Keywords                        : C, D

C:\>exiftool -sep "##" -if "defined ${MyKeywords;NoDups}" -p "MyKeywords-> ${MyKeywords;NoDups}" X:\!temp\Test3.jpg
MyKeywords-> A##B##C##D

C:\>exiftool -sep "##" "-MyKeywords<${MyKeywords;NoDups}" X:\!temp\Test3.jpg
    1 image files updated

C:\>exiftool -MyKeywords X:\!temp\Test3.jpg
Subject                         : A, B, C, D
Keywords                        : A, B, C, D
Title: Re: Problem with Shortcuts and NoDups(1)
Post by: Phil Harvey on May 04, 2017, 07:46:09 AM
Hi StarGeek,

Thanks!!  Without you it could have been a long time before someone tried this feature with a Shortcut tag.

This is fixed by adding " if defined $val" to line 2918 of lib/Image/ExifTool/Writer.pl:

            push @vals, $val if defined $val;

The next release of ExifTool will contain this patch.

But note that the NoDups function may not do exactly what you want with Shortcut tags.  It will remove duplicates only within each source tag.  If, say, Subject contains a value that exists in Keywords, then this duplicate is not removed from the MyKeywords output.  This is because NoDups is applied separately to the value of each of the source tags.  I don't know if this is what you expected/wanted, but I am open to suggestions about how to handle this.

- Phil

Edit:  Thinking about this some more, I think it may make more sense to apply the expression to the combined shortcut value, rather than to its constituent values.  This change would a bit more involved, but I could do this too for the next release.

Edit2: Hmmm.  This still may not give the desired result with regards to the NoDups(1) feature.  For example, if Subject and Keywords contain exactly the same strings (say "a" and "b"), then the combined string will always have duplicates, and running "-mykeywords<${mykeywords;NoDups(1)}" will continually update the file.
Title: Re: Problem with Shortcuts and NoDups(1)
Post by: StarGeek on May 04, 2017, 11:30:04 AM
Quote from: Phil Harvey on May 04, 2017, 07:46:09 AM
But note that the NoDups function may not do exactly what you want with Shortcut tags.  It will remove duplicates only within each source tag. 

Don't worry about then.  I'm perfectly happy with my user defined combine tags and will certainly be able to put NoDups to work in other place.  I'm just glad I was able to find the bug early.
Title: Re: Problem with Shortcuts and NoDups(1)
Post by: Phil Harvey on May 04, 2017, 11:37:25 AM
OK, thanks.  If you don't care one way or the other, I think I prefer the expression operating on the combined string for Shortcut tags (especially since these are combined using the -sep setting as of version 10.51), so I will do this for the next release.

- Phil
Title: Re: Problem with Shortcuts and NoDups(1)
Post by: Phil Harvey on May 05, 2017, 07:56:24 AM
Hi StarGeek,

I've been playing around a bit more with this.  I have worked up the code to allow tags to be combined without the need for a Shortcut.  For example:

exiftool -sep "##" "-subject<${subject+keywords;NoDups}" DIR

It is fun to play with, but I won't be releasing this toy code unless there is potentially a real use for a feature like this.

The above command can already be accomplished using the current version of ExifTool like this:

exiftool -addtagsfromfile @ "-subject-<keywords" "-subject<keywords" DIR

- Phil
Title: Re: Problem with Shortcuts and NoDups(1)
Post by: StarGeek on May 05, 2017, 06:12:21 PM
Quote from: Phil Harvey on May 05, 2017, 07:56:24 AM
It is fun to play with, but I won't be releasing this toy code unless there is potentially a real use for a feature like this.

No worries.  I'm just always looking to reduce the size of my config file. 
Title: Re: Problem with Shortcuts and NoDups(1)
Post by: Phil Harvey on May 05, 2017, 10:22:45 PM
So would it be useful to you then?

- Phil
Title: Re: Problem with Shortcuts and NoDups(1)
Post by: StarGeek on May 06, 2017, 12:41:33 AM
Thank you but it wouldn't be worth it for just me. 
Title: Re: Problem with Shortcuts and NoDups(1)
Post by: Phil Harvey on May 06, 2017, 08:07:15 AM
OK, thanks.