Transferring Label Metadata

Started by mulu, January 13, 2020, 12:19:56 AM

Previous topic - Next topic

mulu

My images have label metadata stored in "Urgency" in the section "XMP-photoshop". This data is stored as an value like 1, 2, etc. I need to copy that value to "Label" in the section "XMP-xmp". In addition to that, I don't just need to copy it but also to change the value to a color, e.g. 1=red, 2=yellow, etc. So

XMP-photoshop/Urgency = 1 converts to XMP-xmp/Label = red
XMP-photoshop/Urgency = 2 converts to XMP-xmp/Label = yellow
etc

How can I achieve this? Note that I have to do this for tens of thousands of images.

StarGeek

Here's an inline command that would work for a quick fix.  Long term, a user-defined tag version would probably be better.
exiftool "-Label<${Urgency#;my %color; @color{1..9} = qw(Black Red Orange Yellow Green Blue Indigo Violet White);$_=$color{$_}}" <FileOrDir>

Replace 1..9 with the number range you want.  Replace the colors with the order you want your colors in.  If you want color names with two or more words, it would require some tweaking.

Remember citizen, the computer is your friend.  Trust the computer.

Ooops, sorry, PnP RPG roots showing there.
* 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).

mulu

Thanks a lot. That seems to work. I don't really understand the syntax, though. The documentation I found only shows simple stuff. Is there some other documentation that explains what you have shown?

Btw, why did you recommend using custom tags? As background information, I am moving from one image cataloging program to another one but the second one can't read all tags from the first one. Hence I am trying to copying/translating tags.

What I kind of can guess is:


  • -Label is the name of the tag I want to write to the file
  • <${...} seems to be some kind of look-up syntax taking various input parameters
  • Urgency# is the target tab but what is the #?
  • my %color seems to be a variable/formula for the target value. But why the "my"?
  • @color defines the variable "%color" and it's a range from 1 to 9
  • That @color is mapped to the color words (qw=quick work?)
  • What is that $_=$color{$_} do at the end?
[/li]
[/list]

StarGeek

Quote from: mulu on January 13, 2020, 02:11:08 PMIs there some other documentation that explains what you have shown?

PerlDoc
That command is basically a bit of perl code using the Advanced formatting feature.  I wouldn't worry too much about it unless you want to get some programming experience.

QuoteBtw, why did you recommend using custom tags?
If this is just a short term procedure, then that command is fine. The reason I'd suggest creating a user defined tag is to prevent errors that might creep in from typing it in or other similar mistakes.  It's just easier to use something like "-Label<UrgencyColor"

Quote
-Label is the name of the tag I want to write to the file
<${...} seems to be some kind of look-up syntax taking various input parameters
...
my %color seems to be a variable/formula for the target value. But why the "my"?

Yep, pretty close.  The my %color; creates a Perl Hash.  The second part matches the numbers 1-9 with the colors in the qw part.  That's just a quick and easy way to create a lookup table.  If you were to use something like "Brick Red", that would require more explicit code because qw treat it as two separate colors.

The my part is how Perl declares a variable.

QuoteUrgency# is the target tab but what is the #?
That's a short version of the -n (printConv) option.  It's used to get the raw number because normally exiftool will display some extra text with some urgency ratings (e.g.  0 (reserved), 1 (most urgent), 5 (normal urgency), etc).  See the XMP tag page for the list.

QuoteWhat is that $_=$color{$_} do at the end?
The $_ is Perl's default variable.  In this context, it holds the value of Urgency.  The $color{$_} is the hash lookup.  For example, if Urgency is 5, then it takes value of the color that has an index of 5 and assigns that back to the default variable.  That makes it so that the new Urgency value is a color, not the number it originally was.
* 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).