Problem with Shortcuts and NoDups(1)

Started by StarGeek, May 03, 2017, 03:32:08 PM

Previous topic - Next topic

StarGeek

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
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

#1
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.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

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. 
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

So would it be useful to you then?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Thank you but it wouldn't be worth it for just me. 
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).