Removing all tags containing a given string.

Started by rothenb, July 11, 2024, 10:36:06 AM

Previous topic - Next topic

rothenb

As the Subject says, I'm looking for the quickest and more efficient way to remove all tags whose value contains a given string. I have found a similar issue in this topic, but I'm not interested in removing the "Unwanted Text", but all of the affected tags themselves, whatever their names. I'm also in doubt because the first reply to that topic says that blanking a tag does not remove it, while another reply almost 5 years later to this other topic says that setting a tag to nothing (i.e. -Description=) would remove it.

To be more accurate, the full process for a group of files would be as follows:
- Remove all tags including a given string (not all files would contain it)
- Remove all tags excepting ICC_Profile, IPTC and XMP (some of these 'could' contain the string above)
- Add or modify some IPTC, XMP and EXIF tags

By the way, I have already used the -TagsFromFile @ option for the second step, but I've been unable to add new IPTC or XMP tags with the same command, being forced to use a new exiftool run for the third step. I wonder if changing the precedence of the second and third steps would do the trick.

Any help?

Phil Harvey

First things first.  Removing tags that contain a specific string.  The post you reference would work, but the new FilterW option was introduced after that post and would be better because it wouldn't rewrite unaffected tags:

exiftool -tagsfromfile @ -all:all -api filterw="$_ = /some string/ ? '' : undef" FILE

But yes, this will blank these tags instead of deleting them because it isn't assigning them to nothing (ie. "-tag="), but instead is copying an empty value to the tag.  I can't think of an easy way to delete them in the same step, but running this command afterward should delete any empty tags:

exiftool -all-= FILE

To remove everything but selected groups:

exiftool -all= --exif:all --xmp:all --iptc:all --iptc_profile:all FILE

I hate to say it, but it would be simplest to keep this command separate from the others, but you could also write any new XMP, IPTC or EXIF tags you want in this command.

- 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: rothenb on July 11, 2024, 10:36:06 AM- Remove all tags excepting ICC_Profile, IPTC and XMP (some of these 'could' contain the string above)
- Add or modify some IPTC, XMP and EXIF tags

By the way, I have already used the -TagsFromFile @ option for the second step, but I've been unable to add new IPTC or XMP tags with the same command, being forced to use a new exiftool run for the third step. I wonder if changing the precedence of the second and third steps would do the trick.

To clarify the bolded part, from the docs on the -TAG[+-^]=[VALUE] option (emphasis mine)
QuoteMany tag values may be assigned in a single command. If two assignments affect the same tag, the latter takes precedence (except for list-type tags, for which both values are written).

So if you modify or add a tag, and then remove all tags, the latter removal takes precedent. You want to do any removals first, then modify or add any tags.

* 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).

rothenb

First of all, thank you both for such a quick response and, of course, thanks again to Phil for this so powerful tool. I had used it before but only occasionally, and it is only now that I have started to go more in depth. I have several thousand digital photos from quite a few years (not to mention the digitalized analogic ones) so I'm now working on a way to improve and systematize the metadata management. I'm a Mac user, I already have my own PHP application to address the full process after exporting from Photos, to do the metadata stuff (using some libraries for that), build the pages and sync the whole with my server. However, after more testing with exiftool I have seen that it offers many more possibilities than the libraries. As I also see an added advantage on having the same 'metadata ecosystem' in both the application and the command line, I'm migrating the application to use it, with very satisfactory results so far.

Quote from: StarGeek on July 11, 2024, 11:15:31 AMSo if you modify or add a tag, and then remove all tags, the latter removal takes precedent. You want to do any removals first, then modify or add any tags.

For some reason I had the idea that using TagsFromFile was the way to delete all metadata keeping some tags or groups. So I first tested something as:

$ exiftool -all= -TagsFromFile @ -ICC_Profile -IPTC -XMP -serialnumber=0 -lensserialnumber=0 -imagedescription='The description here' -copyright='My copyright notice here' -objectname='M52_PB7635.JPG' -by-line='J. Smith' -description='The description here' -overwrite_original PB7635.JPG

With this command, yes, ICC_Profile, IPTC and XMP were there, and also the added EXIF serialnumber, lensserialnumber, imagedescription and copyright tags, but it silently 'failed' to add IPTC objectname and by-line and also XMP description, without errors or warnings at all. I solved it with a new exiftool command run for these 'failed' tags, but according to your explanations I guess the command doesn't work like I thought but the other way around, that is, first adding the new tags, but laterly deleting all and restoring only the 'original' ICC_Profile, IPTC and XMP ones...

Quote from: Phil Harvey on July 11, 2024, 11:01:08 AMTo remove everything but selected groups:
exiftool -all= --exif:all --xmp:all --iptc:all --iptc_profile:all FILE
I hate to say it, but it would be simplest to keep this command separate from the others, but you could also write any new XMP, IPTC or EXIF tags you want in this command.

Anyway this command looks much cleaner, and being able to add the new tags in the same step is definitely a plus for my use case.

Thanks again!

StarGeek

Quote from: rothenb on July 11, 2024, 05:15:11 PMFor some reason I had the idea that using TagsFromFile was the way to delete all metadata keeping some tags or groups. So I first tested something as:

$ exiftool -all= -TagsFromFile @ -ICC_Profile -IPTC -XMP -serialnumber=0 -lensserialnumber=0 -imagedescription='The description here' -copyright='My copyright notice here' -objectname='M52_PB7635.JPG' -by-line='J. Smith' -description='The description here' -overwrite_original PB7635.JPG

With this command, yes, ICC_Profile, IPTC and XMP were there, and also the added EXIF serialnumber, lensserialnumber, imagedescription and copyright tags, but it silently 'failed' to add IPTC objectname and by-line and also XMP description, without errors or warnings at all. I solved it with a new exiftool command run for these 'failed' tags, but according to your explanations I guess the command doesn't work like I thought but the other way around, that is, first adding the new tags, but laterly deleting all and restoring only the 'original' ICC_Profile, IPTC and XMP ones...

When you use simpley -IPTC and -XMP, you are doing a block copy, that is copying the entire data block unchanged. Change these to -IPTC:All and -XMP:All. This will copy each tag individually and allow other alterations.

Offhand, I haven't looked at the interactions between copying blocks and setting tags, so it may be something Phil can shed some light on.

* 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).

Phil Harvey

If you copy a block then any individual tag you were trying to change within that block won't be affected.

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