Appending/copying multiple tags in one command line

Started by Oldariel, January 20, 2021, 12:52:42 PM

Previous topic - Next topic

Oldariel

Hello,

I've used exiftool multiple times over the years for simple tasks with bulk metadata editing. Up until now I have always managed to figure out what to do without asking questions, by reading thorugh the resource page and forums. But I could use some help now.

I'm trying to copy tags from IPTC:Country-PrimaryLocationName, IPTC:Sub-location, IPTC:Country-PrimaryLocationCode, IPTC:Province-State to xmp-digiKam:TagsList. I have figured out the command to do so. The tags don't get overwritten, but are appended, as I want them to:

"-xmp-digiKam:TagsList+<IPTC:Country-PrimaryLocationName"  -m IMG_2707.JPG

I have to repeat the command (modified appropriately) for all the tags. The commands work as expected, the tags are appended. I would however like to combine all four into a single command line and apply this combined command to all the .jpg in the current directory (or a specified directory). I have the feeling this is really super easy to do, somehow in the sense of "common mistake 4. Writing/Copying Multiple Tags", but I can't figure it out.

I also have a trickier question. Would it be possible to add the string "Location/" in front of each tag while copying the tags? So, for example, the original tag "Slovenia" from IPTC:Country-PrimaryLocationName would be copied over as "Location/Slovenia" to -xmp-digiKam:TagsList? The idea is to get hierarchical tags in the digiKam tags namespace.

Jernej

StarGeek

This is one that I mess up on all the time.

See FAQ #17, near the end.
   Note there is a complication when copying multiple tags to a single list tag: Here, any assignment to a tag overrides earlier assignments to the same tag in the command.

So the basic command would be something like this:
exiftool -AddTagsFromFile @ "-TagsList+<Country-PrimaryLocationName" "-TagsList+<Sub-location" "-TagsList+<Country-PrimaryLocationCode" "-TagsList+<Province-State" /path/to/files

But to expand it to "Location/" to the front, you would do this
exiftool -AddTagsFromFile @ "-TagsList+<Location/$Country-PrimaryLocationName" "-TagsList+<Location/$Sub-location" "-TagsList+<Location/$Country-PrimaryLocationCode" "-TagsList+<Location/$Province-State" /path/to/files

In the case of all these tags, the names are unique, so there's no need to include the group name.
* 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).

Oldariel

Oh wow, thanks for the extremly quick reply  :). So the AddTagsFromFile option is key here. I might have skipped over the explanations under 17. FAQ to quickly. I have reread it now and understood it.

First I had to spend a couple of minutes figuring out though, why your command does not have the "xmp-digiKam:" part anywhere in it.  :) My first reaction was - ok, but where will the tags get copied to? And what does TagsList mean? Took me a while to get it  :) - I didn't know you can abbreviate like this, ommiting the namespace.

Oldariel

Omg, I'm slow  ;D. I have just now realized you have explained this to me in your last sentence.  ;D

Oldariel

Sorry for the rapidfire posting, but I'm playing around with this a little bit more, just for the fun of it.

If I would like to prevent the tags being added when the same tag is already present in TagsList, how would I accomplish that? When trying to adapt the command as suggested in 17. FAQ, "to prevent duplication when adding new items", I tried with "-=" and came up with this:

Exiftool "-TagsList-=Location/$IPTC:City" "-TagsList-=Location/$Country-PrimaryLocationName" "-TagsList-=Location/$Sub-location" "-TagsList-=Location/$Country-PrimaryLocationCode" "-TagsList-=Location/$Province-State"  -AddTagsFromFile @ "-TagsList+<Location/$IPTC:City" "-TagsList+<Location/$Country-PrimaryLocationName" "-TagsList+<Location/$Sub-location" "-TagsList+<Location/$Country-PrimaryLocationCode" "-TagsList+<Location/$Province-State"

I added IPTC to IPTC:City, beacuse City surely isn't unique.

It does not work though. The tags get duplicated. I tried to use just the the Exiftool "-TagsList-=Location/$IPTC:City" part and this does not remove the tags already present in TagsList. Is this because I'm defining the tag incorrectly? There is no error message, the file just dont gets modified. 

Phil Harvey

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

Oldariel

Hello,

and thanks for the pointer. But have some patience with me please.

Is this:

"=" is used to assign a simple tag value, and the source operand is a string that is written directly to the destination tag.

the problem?

Do I understand this correctly - when using = (or -= as I tried to do)  the source operand can only be a simple string and you cannot use the "$" symbol in it?


Phil Harvey

If you use "=", or "+=" or "-=", the exact value you specify is used.  (ie. there is no interpolation of tag names in the string).

You must use "<" or "+<" or "-<" if you want to copy, add or delete a string that contains another tag value (with a leading "$" symbol).

I chose to do it this way for backward compatibility.  If the same operator was used to copy tag values, then the "$" would have to be escaped somehow if you had a string that contained a dollar sign (eg. -comment="This cost me $1.50" wouldn't work)

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

StarGeek

Quote from: Oldariel on January 21, 2021, 05:40:58 AMI added IPTC to IPTC:City, beacuse City surely isn't unique.

While City is not unique, it is the location for the same exact data in IPTC and IPTC Core (which is XMP) (see the IPTC spec on City).  So unless some other software messed up and wrote different data to the two tags (unlikely), you could use simply City without problems. And if you're writing to City, it's actually better to not use a group so that exiftool would update XMP:City and IPTC:City if they both exist.

Quote from: Oldariel on January 21, 2021, 04:30:35 AMI didn't know you can abbreviate like this, ommiting the namespace.

IMO, this is a best practice (see KISS principle), especially when you're starting out dealing with metadata because metadata is such a hot mess to try and understand.  Personally, I almost never give anything more than a leading group 0 location (XMP, EXIF, or IPTC).  The only time I will give an exact tag name is when the tag I want to write is an "Avoid" tag (see 4th paragraph below the table on the Tag Names page that starts with "A plus sign").
* 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).

Oldariel

Hi,

and thank you both for your answers. I now have a much better understaning of how these comands work and have really grasped the difference betwenn "=" for simple as-is and "<" for source to destination. At first I didn't quite get the concpet that removing a tag also required a source, but it makes perfect sense, since you want to use $ to define part of the tag to be removed by using that source. I'll also stop using the exact name tags, City worked perfectly well in this case. I assume when reading data it will read the IPTC:City or XMP-iptcCore:City, if at least one of those is present.

The final combined command that works as I want it to (adds new tags but does not ovewrite existing tags and prevents duplicates from being created if the same tags are already present) is as follows:

Exiftool -AddTagsFromFile @ "-TagsList-<Location/$City" "-TagsList-<Location/$Country-PrimaryLocationName" "-TagsList-<Location/$Sub-location" "-TagsList-<Location/$Country-PrimaryLocationCode" "-TagsList-<Location/$Province-State" "-TagsList+<Location/$City" "-TagsList+<Location/$Country-PrimaryLocationName" "-TagsList+<Location/$Sub-location" "-TagsList+<Location/$Country-PrimaryLocationCode" "-TagsList+<Location/$Province-State" "C:\Users\Jernej\Pictures\Test2" -overwrite_original

Thanks again for the help and explanations.