How to append from two manipulated tags into another tag?

Started by TushyBhutt, March 11, 2023, 06:06:16 PM

Previous topic - Next topic

TushyBhutt

I have a situation where there are two tags in the PNG metadata that I want to copy into a Lightroom Hierarchical data tag.

The first PNG tag is PNG:Parameters and I am using regex within it to format metadata to copy into -XMP-LR:HierarchicalSubject. I am doing the same for PNG:Extras, but copying the output from that overwrites the -XMP-LR:HierarchicalSubject tag with the new data.

I've tried the following (NOTE that the regex commands within the tag manipulation has been removed for simplicity)"

-sep "##" "-XMP-lr:HierarchicalSubject<${PNG:extras; regex stuff -XMP-lr:HierarchicalSubject<${PNG:parameters; regex stuff}" 

Result: EXTRAS value going in, but not PARAMETERS


-sep "##" "-XMP-lr:HierarchicalSubject<${PNG:extras; regex stuff}" "-XMP-lr:HierarchicalSubject<${PNG:parameters; regex stuff}"

Result: EXTRAS value going in, but not PARAMETERS


-sep "##" "-XMP-lr:HierarchicalSubject<${PNG:extras; regex stuff}" "-XMP-lr:HierarchicalSubject+=${PNG:parameters; regex stuff}"

Result: EXTRAS value and PARAMETERS Regex commands going in, not result of PARAMETERS manipulation


-sep "##" "-XMP-lr:HierarchicalSubject<${PNG:extras; regex stuff}" "-XMP-lr:HierarchicalSubject+${PNG:parameters; regex stuff}" 

Result: EXTRAS value going in, but not PARAMETERS

-sep "##" "-XMP-lr:HierarchicalSubject<${PNG:extras; regex stuff}" "-XMP-lr:HierarchicalSubject=${PNG:parameters; regex stuff}"

Result: EXTRAS value and PARAMETERS Regex commands going in, not result of PARAMETERS manipulation

I even tried copying the PNG fields into XMP-LR:HierarchicalSubject with no manipulation but that didn't seem to work either (the last field in the sequence overwrites the first). 

Does anyone have any pointers on how to do this?  Thanks!

TushyBhutt

I figured it out!  For anyone looking at this in the future, the commands format is:


-addtagsfromfile @ "-XMP-lr:HierarchicalSubject+<${PNG:extras; regex string}" "-XMP-lr:HierarchicalSubject+<${PNG:parameters; regex string}"

Phil Harvey

The -addTagsFromFile @ was the trick.  You only need +< to add to existing HierarchicalSubject items already in the file, otherwise < would do to add both items you are writing.

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

TushyBhutt

#3
Oh, good to know!

TushyBhutt

If I wanted to further manipulate the metadata in the new tag, can I chain the operation?  I tried the following and none of them worked:

-sep "##" -addtagsfromfile @ "-XMP-xmp:advisory<${PNG:parameters}" "-XMP-xmp:advisory<${PNG:extras}" "-XMP-lr:HierarchicalSubject<${XMP-xmp:advisory}"

-sep "##" -addtagsfromfile @ "-XMP-xmp:advisory<${PNG:parameters}" "-XMP-xmp:advisory<${PNG:extras}" -tagsfromfile "-XMP-lr:HierarchicalSubject<${XMP-xmp:advisory}"


But doing two separate commands did:


-sep "##" -addtagsfromfile @ "-XMP-xmp:advisory<${PNG:parameters}" "-XMP-xmp:advisory<${PNG:extras}"

"-XMP-lr:HierarchicalSubject<${XMP-xmp:advisory}"



I am sure could do this: XMP-lr:HierarchicalSubject<${PNG:extras; regex string}" "-XMP-lr:HierarchicalSubject<${PNG:parameters; regex string}" but by placing both EXTRAS and PARAMETERS into a temporary tag (and deleting it after), I was hoping to save on some needed Regex operations that were common to both EXTRAS and PARAMETERS
 

Phil Harvey

The source tags of a copy argument are always the tags from the original file.

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

TushyBhutt

Quote from: Phil Harvey on March 12, 2023, 07:39:52 AMThe source tags of a copy argument are always the tags from the original file.

- Phil

So in the case I had, until I do the first command to copy the two sources into the third, it's not written to the file until I press ENTER, and that's why source three can't be used to manipulate text into source four?

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

TushyBhutt

So the -execute flag won't work either, like below?  If -execute is to do what it's name suggests, does it not write to the file and then carry on with the next command after -execute?

-sep "##" -addtagsfromfile @ "-XMP-xmp:advisory<${PNG:parameters}" "-XMP-xmp:advisory<${PNG:extras}" -execute "-XMP-lr:HierarchicalSubject<${XMP-xmp:advisory}"


Phil Harvey

-execute will work because it is the same as running 2 commands.  But your command should look like this:

exiftool -sep "##" -addtagsfromfile @ "-XMP-xmp:advisory<${PNG:parameters}" "-XMP-xmp:advisory<${PNG:extras}" -execute "-XMP-lr:HierarchicalSubject<XMP-xmp:advisory" -common_args FILE

I'm assuming you are using string interpolation in the first command because you need to use a regex.  I have removed that for the second command to copy it as a list.  (See the "copying tags" description in FAQ 17.)

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

TushyBhutt

Quote from: Phil Harvey on March 12, 2023, 08:15:14 PM-execute will work because it is the same as running 2 commands.  But your command should look like this:

exiftool -sep "##" -addtagsfromfile @ "-XMP-xmp:advisory<${PNG:parameters}" "-XMP-xmp:advisory<${PNG:extras}" -execute "-XMP-lr:HierarchicalSubject<XMP-xmp:advisory" -common_args FILE

I'm assuming you are using string interpolation in the first command because you need to use a regex.  I have removed that for the second command to copy it as a list.  (See the "copying tags" description in FAQ 17.)

- Phil

Thanks. I think I may actually need to do the opposite.  The first step of copying metadata to a temporary field requires no regex, it will will be the next step that does.  I'll fiddle around with the string interpolation to see what works and what does not