Bulk search and replace keywords in Subject

Started by brunos, November 18, 2020, 11:46:33 AM

Previous topic - Next topic

brunos

Hi all,

I need to replace a plenty of keywords in a plenty of photos. After I've read a proposed solution to another user (https://exiftool.org/forum/index.php?topic=9934.msg51669#msg51669), I've performed proposed steps but, unfortunately, it doesn't really work for me. As the last update on that topic was at March, 2019, and the forum suggested that I start a new topic, here I am.

My system is Windows 10 1909 64-bit and my exiftool is the latest one, 12.10.

I've copied the config from the original topic, and applied a necessary change in a Data section that corresponds to my needs. My data sections looks like:

__DATA__
cartellitenuti||cartelli:tenuti
dallalto||dall:alto

The test expression looks like to work fine:

C:\Users\Bruno\Desktop\4fldtemp>exiftool -config ReplacementKeywords.config -Subject -ReplacementKeywords 1-IMG_0325.jpg
Subject                         : cartellitenuti, CL1, dallalto, grp30a, LA_PRIGIONE_NON_├¿_LA_SOLUZIONE, UNTIL_EVERY_CAGE_IS_EMPTY
Replacement Keywords            : cartelli:tenuti, CL1, dall:alto, grp30a, LA_PRIGIONE_NON_├¿_LA_SOLUZIONE, UNTIL_EVERY_CAGE_IS_EMPTY

I guess it finds the replacement keywords for two of five keywords, which is the expected result.

But, when I execute the replacement command as proposed in the original post, I've got a "failed condition" for any image, and any kind of replacement keywords:

C:\Users\Bruno\Desktop\4fldtemp>exiftool -config ReplacementKeywords.config -if "$ReplacementKeywords" "-Subject<ReplacementKeywords" 1-IMG_0325.jpg
    1 files failed condition

What I'm doing wrong? I attach the test picture and the config I'm using (credit to StarGeek)

Thanks!
Bruno

StarGeek

Quote from: brunos on November 18, 2020, 11:46:33 AMand the forum suggested that I start a new topic, here I am.

And thank you for that.  Necroposting is one of my biggest pet peeves.

Heh, I don't even remember making that config file, but testing you files here show the same results and I can't figure out off hand why.  I'll dig into and see what the problem is.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

I can't even get the original to work using the original list.  And looking closer, I'm not sure if it even worked in the first place.  But it must have at one point.

Anyway, it calls for a complete re-write.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

AAAANNNDDD... I just rewrote it to do the exact opposite of what the original did.  I now have a config file that has a list of words which will get replaced with the main keyword, where the original took a single keyword and replaced it with a list of keywords.

Back to the drawing board.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Ok the problem seem seems to lie in my misunderstanding of the __DATA__ construct.  What seems to be happening is the __DATA__ is read once and doesn't get reset for subsequent checks.  So when you just display ReplacementKeywords, the data is only read once but adding the -if check causes it to attempt to read the data four times, which works on the first pass but every subsequent pass ends up with the changed flag set to 0 (unchanged).

So the data read part needs a rewrite and possibly a different way of embedding the data.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Resetting the Data section requires saving the current Data position and the setting it back to that number, but I figured out a way to do it with minimal changes.  I might go back and rewrite a few bits of this config, though.

And thanks for figuring out this problem and let me know if you encounter any other errors.  The original question never had a follow up on if it worked or not and I didn't do a lot of testing on it to begin with.

Example output:
C:\>exiftool -config ReplacementKeywords.config -g1 -a -s -if "$ReplacementKeywords" -Subject -ReplacementKeywords Y:\!temp\ccccc\m\1-IMG_0325.jpg
---- XMP-dc ----
Subject                         : cartellitenuti, CL1, dallalto, grp30a, LA_PRIGIONE_NON_è_LA_SOLUZIONE, UNTIL_EVERY_CAGE_IS_EMPTY
---- Composite ----
ReplacementKeywords             : cartelli:tenuti, CL1, dall:alto, grp30a, LA_PRIGIONE_NON_è_LA_SOLUZIONE, UNTIL_EVERY_CAGE_IS_EMPTY

C:\>exiftool -config ReplacementKeywords.config -P -overwrite_original -if "$ReplacementKeywords" "-Subject<ReplacementKeywords" Y:\!temp\ccccc\m\1-IMG_0325.jpg
    1 image files updated

C:\>exiftool -config ReplacementKeywords.config -g1 -a -s -if "$ReplacementKeywords" -Subject -ReplacementKeywords Y:\!temp\ccccc\m\1-IMG_0325.jpg
    1 files failed condition

C:\>exiftool -config ReplacementKeywords.config -g1 -a -s -Subject -ReplacementKeywords Y:\!temp\ccccc\m\1-IMG_0325.jpg
---- XMP-dc ----
Subject                         : cartelli:tenuti, CL1, dall:alto, grp30a, LA_PRIGIONE_NON_è_LA_SOLUZIONE, UNTIL_EVERY_CAGE_IS_EMPTY
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

brunos

Thank you very much!!! I apologize again to unbury an oldie - but I've searched all around and yours was the potential best fitter!!!

Will try it ASAP and will let you know!

Kindest regards
Bruno

brunos

Hi StarGeek!

it works, with a little inconvenience which perhaps is not an error: it doesn't replace the keyword, it adds a new one.

In other words, in the test pics, I find both "cartellitenuti" and "cartelli:tenuti", both "dallalto" and "dall:alto". Is it something that can be changed, so it would replace the "cartellitenuti" with "cartelli:tenuti" (or add the "cartelli:tenuti" and then remove "cartellitenuti")?

PS. Unfortunately, my scripting capabilities are limited to a bit of VB.Net and a bit of Autoit; Perl syntax is, for me, far far away behind the high mountains :-( so no chance that I try to dig it on my own... Sorry for being a pest!

Kindest regards
Bruno

StarGeek

Quote from: brunos on November 19, 2020, 04:32:59 AM
it works, with a little inconvenience which perhaps is not an error: it doesn't replace the keyword, it adds a new one.

Are you viewing the data with exiftool or with some other program?

If the latter, then the "duplicate" is probably populated from the IPTC:Keywords or maybe HierarchicalSubject.  Run this to double check
exiftool -G1 -a -s -Keywords -Subject -HierarchicalSubject /path/to/files/

In other words, in the test pics, I find both "cartellitenuti" and "cartelli:tenuti", both "dallalto" and "dall:alto". Is it something that can be changed, so it would replace the "cartellitenuti" with "cartelli:tenuti" (or add the "cartelli:tenuti" and then remove "cartellitenuti")?
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

brunos

Good hint! Effectively it is as you say:
C:\Users\Bruno\Desktop\4fldtemp>exiftool -G1 -a -s -Keywords -Subject -HierarchicalSubject -ext jpg C:\Users\Bruno\Desktop\4fldtemp
======== C:/Users/Bruno/Desktop/4fldtemp/1-IMG_0325.jpg
[IPTC]          Keywords                        : cartellitenuti, CL1, dallalto, grp30a, UNTIL_EVERY_CAGE_IS_EMPTY
[XMP-dc]        Subject                         : cartelli:tenuti, CL1, dall:alto, grp30a, UNTIL_EVERY_CAGE_IS_EMPTY
======== C:/Users/Bruno/Desktop/4fldtemp/2-IMG_0326.jpg
[IPTC]          Keywords                        : bandiere, BORN_TO_BE_WILD_STOP_CASTELLER, cartellitenuti, dadietro, grp30a, RISE_UP_4_CLIMATE_JUSTICE
[XMP-dc]        Subject                         : bandiere, BORN_TO_BE_WILD_STOP_CASTELLER, cartelli:tenuti, dadietro, grp30a, RISE_UP_4_CLIMATE_JUSTICE
    1 directories scanned
    2 image files read


What can I do to avoid it?

Thanks for your patience and helpfulness!

Kindest regards
Bruno

brunos

I think I've found how to do it:

C:\Users\Bruno\Desktop\4fldtemp>exiftool -config ReplacementKeywords.config -P -overwrite_original -if "$ReplacementKeywords" "-Subject<ReplacementKeywords" "-Keywords<ReplacementKeywords" -ext jpg -r C:\Users\Bruno\Desktop\4fldtemp

C:\Users\Bruno\Desktop\4fldtemp>exiftool -G1 -a -s -Keywords -Subject -HierarchicalSubject -ext jpg C:\Users\Bruno\Desktop\4fldtemp
======== C:/Users/Bruno/Desktop/4fldtemp/1-IMG_0325.jpg
[IPTC]          Keywords                        : cartelli:tenuti, CL1, dall:alto, grp30a, UNTIL_EVERY_CAGE_IS_EMPTY
[XMP-dc]        Subject                         : cartelli:tenuti, CL1, dall:alto, grp30a, UNTIL_EVERY_CAGE_IS_EMPTY
======== C:/Users/Bruno/Desktop/4fldtemp/2-IMG_0326.jpg
[IPTC]          Keywords                        : bandiere, BORN_TO_BE_WILD_STOP_CASTELLER, cartelli:tenuti, dadietro, grp30a, RISE_UP_4_CLIMATE_JUSTICE
[XMP-dc]        Subject                         : bandiere, BORN_TO_BE_WILD_STOP_CASTELLER, cartelli:tenuti, dadietro, grp30a, RISE_UP_4_CLIMATE_JUSTICE
    1 directories scanned
    2 image files read

Will try to test it on 400 replacement keywords and will see...

Thanks a million!!

Very grateful kindest regards
Bruno

StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype