clear all xmp subjects and iptc keywords when using an argument file

Started by Yalkov, December 07, 2021, 01:08:06 AM

Previous topic - Next topic

Yalkov

I am trying to clear all xmp subject and iptc tags.
I am making an argument file for exif tool.

I have had success with this, where I immediately clear and save the new file:

-xmp-dc:subject=
C:\photos\file.jpg
-overwrite_original
-execute


but if I try this, the file's previous subjects/iptc tags remain in the file (although it does receive the new ones)

-xmp-dc:subject=
-xmp-dc:subject-=trip 2018
-xmp-dc:subject+=trip 2018
C:\photos\file.jpg
-overwrite_original
-execute



How do I delete all xmp subjects/iptc keywords in an argument file?

StarGeek

From FAQ #17
    Note: Using "=" is equivalent to "+=" in any command where the same List-type tag is set with "+=" or "-=" in another assignment. (ie. existing items will be preserved unless specifically deleted with "-=".)

There's no reason to use -=/+= when you've just cleared out all the Subject tag entries.  Just add in your entries afterwards
-xmp-dc:subject=
-xmp-dc:subject=trip 2018
C:\photos\file.jpg
-overwrite_original
-execute
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Yalkov

Thanks for the tip, but this

-xmp-dc:subject=
-xmp-dc:subject=trip 2018
C:\photos\file.jpg
-overwrite_original
-execute


is still not removing the existing xmp tags. I check with "exiftool -G1" and they are still present afterward. I still have to do two overwrite and execute commands. One to clear the file, one to write the new tags, but this is not efficient. Is there a better way to do this?

Further, with the command you posted, exif tool does not tell me a file has been updated, either. Usually it prints this:

  1 image files updated
{ready}


but it prints nothing with that command.

StarGeek

It works correctly here
C:\>exiftool -g1 -a -s -subject y:\!temp\Test4.jpg
---- XMP-dc ----
Subject                         : Keyword 1, Keyword 2

C:\>type temp.txt
-xmp-dc:subject=
-xmp-dc:subject=trip 2018
y:\!temp\Test4.jpg
-overwrite_original
C:\>exiftool -@ temp.txt
    1 image files updated

C:\>exiftool -g1 -a -s -subject y:\!temp\Test4.jpg
---- XMP-dc ----
Subject                         : trip 2018
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Yalkov

Thank you for your help! I found that the error was that I was mistakenly still using "-=" and "+=" instead of just "=".

When I used "-=" I expected exiftool to do nothing if the keyword was not in the file. I have used it like this in the past successfully. But when paired like this, with clearing the xmp subjects first:

-xmp-dc:subject=
-xmp-dc:subject-=trip 2018
-xmp-dc:subject+=trip 2018
C:\photos\file.jpg
-overwrite_original
-execute


It leads to the problems I talked about. I would expect the order of commands to first clear the subject, then attempt to remove "trip 2018" if it exists, and then add "trip 2018" but this is not what happens, as it all fails to work.

I am trying to understand exiftool better, so it is just not possible to use the commands I tried above because of using the -xmp-dc:subject-=trip 2018 line? Or should it have worked and another problem is at play?


Phil Harvey

Quote from: Yalkov on December 07, 2021, 05:46:10 AM
-xmp-dc:subject=
-xmp-dc:subject-=trip 2018
-xmp-dc:subject+=trip 2018
C:\photos\file.jpg
-overwrite_original
-execute


I would expect the order of commands to first clear the subject, then attempt to remove "trip 2018" if it exists, and then add "trip 2018" but this is not what happens, as it all fails to work.

I don't understand your logic.  If the subject is cleared, then "trip 2018" can not exist.

However, this command will not clear the subject because as soon as you use += or -=, ExifTool assumes you want to preserve the existing values (otherwise, why use += and -=?).  So the effect of this command will be to add "trip 2018" without duplicating this entry.

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

Yalkov

Hi Phil,

Thanks for replying. First let me say I really love exiftool, it does so much, and working with other libraries is a pain just to get them to reliably read a file, but with exiftool I was able to do this in 10 minutes.

Maybe I don't understand what "-=" or "+=" means. I thought "-=" meant "delete the keyword if it exists, preserve other keywords" and "+=" meant "add the keyword if it doesn't exist, preserve other keywords" This is how I read the line from FAQ#17,

QuoteTo prevent duplication when adding new items, specific items can be deleted then added back again in the same command. For example, the following command adds the keywords "one" and "two", ensuring that they are not duplicated if they already existed in the keywords of an image:

exiftool -keywords-=one -keywords+=one -keywords-=two -keywords+=two DIR

And how I read this line from http://exiftool.sourceforge.net/exiftool_pod.html#WRITING-EXAMPLES ,

Quoteexiftool -credit-=xxx dir

   Delete Credit information from all files in a directory where the Credit value was xxx.


I could not find any other examples of "-=".

The logic then would be, reading from left to right, is to 1) delete all keywords, 2) remove "trip 2018" if it exists, preserve existing keywords, 3) add "trip 2018", preserving existing keywords. The end result would be a single keyword, "trip 2018"

But, if I am understanding you right, it seems that exiftool is interpreting the entire command, ignoring the first part (xmp-dc:subject=) because of the second part ("-=").
You are right, it does not make sense the way I have described it, but I am not using exiftool directly, but instead outputting commands manually from other programs into argument files. So clearing the subject is part of generated command, I just defaulted to always adding a keyword by both using the "-=" and "+=" to prevent duplication since it seemed the safest way to do things.

Please let me know if I am understanding any of this badly. Is there some general idea to know of which command will have precedence, so that I can tell if I use "keyword-=" then "keyword=" will not work?

StarGeek

Quote from: Yalkov on December 07, 2021, 10:49:43 AM
Maybe I don't understand what "-=" or "+=" means. I thought "-=" meant "delete the keyword if it exists, preserve other keywords"

This is correct.

Quoteand "+=" meant "add the keyword if it doesn't exist, preserve other keywords"

This is not correct.  The keyword is added regardless of whether it exists or not.  Exiftool doesn't do any verification of existing keywords.  It leaves that up to you.

QuoteThe logic then would be, reading from left to right, is to 1) delete all keywords, 2) remove "trip 2018" if it exists, preserve existing keywords,

Except "trip 2018" cannot exist, as you have already deleted all the keywords.  Which is why all you need to do is
exiftool -Subject= -Subject="trip 2018" file.jpg
or even better, you don't need to clear at all as just setting Subject to a value will clear all other entries (see this example)
exiftool -Subject="trip 2018" file.jpg

Quote3) add "trip 2018", preserving existing keywords. The end result would be a single keyword, "trip 2018"

But there are no keywords to preserve, as you have cleared them.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Yalkov

Ok! Thanks for clarifying.

Would it be expected that

-xmp-dc:subject=
-xmp-dc:subject+=trip 2018
file.jpg
-overwrite_original
-execute


would preserve all pre-existing keywords in the file because  "-xmp-dc:subject+=trip 2018" causes "-xmp-dc:subject=" to be ignored?

StarGeek

Quote from: Yalkov on December 07, 2021, 11:10:28 AMwould preserve all pre-existing keywords in the file because  "-xmp-dc:subject+=trip 2018" causes "-xmp-dc:subject=" to be ignored?

Yes
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).