Set tag to undef if substitution fails using api filter

Started by StarGeek, February 26, 2018, 10:33:55 PM

Previous topic - Next topic

StarGeek

I'm trying to set a tag to undef if a substitution fails while using -api filter.  If I'm copying a tag and using the substitution in the copy, it will work. 

For example, this works fine.
C:\>exiftool -s -description -keywords Y:\!temp\zzz
======== Y:/!temp/zzz/Test_1.jpg
Description                     : Group 1, Group 2, Group 3
======== Y:/!temp/zzz/Test_2.jpg
Description                     : And now for something completely different
    1 directories scanned
    2 image files read

C:\>exiftool "-keywords<${description;$_=(s/^(.*), (.*), (.*$)/$3 - $2 - $1/) ? $_ : undef}"  Y:\!temp\zzz
Warning: [minor] Advanced formatting expression returned undef for 'description' - Y:/!temp/zzz/Test_2.jpg
Warning: No writable tags set from Y:/!temp/zzz/Test_2.jpg
    1 directories scanned
    1 image files updated
    1 image files unchanged

C:\>exiftool -s -description -keywords Y:\!temp\zzz
======== Y:/!temp/zzz/Test_1.jpg
Description                     : Group 1, Group 2, Group 3
Keywords                        : Group 3 - Group 2 - Group 1
======== Y:/!temp/zzz/Test_2.jpg
Description                     : And now for something completely different
    1 directories scanned
    2 image files read


But if I try to use API Filter instead
C:\>exiftool -api "filter=$_=(s/^(.*), (.*), (.*$)/$3 - $2 - $1/) ? $_ : undef" "-keywords<description" Y:\!temp\zzz
    1 directories scanned
    2 image files updated

C:\>exiftool -s -description -keywords Y:\!temp\zzz
======== Y:/!temp/zzz/Test_1.jpg
Description                     : Group 1, Group 2, Group 3
Keywords                        : Group 3 - Group 2 - Group 1
======== Y:/!temp/zzz/Test_2.jpg
Description                     : And now for something completely different
Keywords                        : And now for something completely different
    1 directories scanned
    2 image files read


As you can see, in the Test_2, the description is passed through unaltered.  If the false branch of the conditional is set to something other than undef, then that value will be set.
C:\>exiftool -api "filter=$_=(s/^(.*), (.*), (.*$)/$3 - $2 - $1/) ? $_ : 'Fail'" "-keywords<description" Y:\!temp\zzz
    1 directories scanned
    2 image files updated

C:\>exiftool -s -description -keywords Y:\!temp\zzz
======== Y:/!temp/zzz/Test_1.jpg
Description                     : Group 1, Group 2, Group 3
Keywords                        : Group 3 - Group 2 - Group 1
======== Y:/!temp/zzz/Test_2.jpg
Description                     : And now for something completely different
Keywords                        : Fail
    1 directories scanned
    2 image files read


Is it a bug? This was just something that caught me off guard trying to figure out.  I've just grown too fond of API Filter, I guess.
"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

This is by design.  Read the Filter option description.  I can't remember why I did it this way, but I probably had a reason.

- 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

Gotcha.  Not a problem then.

Thinking back, might it have had something to do with list type tags?  I faintly remember some of my early testing having differing results at one point, but I wasn't paying enough attention to narrow it down.
"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

Yes, an undef entry in a list could be a potential problem.

- 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 ($).