All,
I need to copy a converted xmp:RegionName to Keywords and Subject, but under two conditions: the xmp:RegioneName is not to be copied if it exists already in the format "t:prefix:Name:Lastname" and the second char of the RegionName prefix must be the uppercase "N".
For example, if the xmp:RegionName is aN0F Name Lastname, should be copied to Keywords and Subject by adding a t: as a prefix, and replacing spaces by ":", for example t:aN0F:Name:Lastname. The inclusion rule is that the second char must be uppercase N and other characters are copied as they are. If the second char is not a N, nothing should be copied to Keywords and Subject.
I've had a gentle contribution from this forum for a case with an unconditional copying (five calls in a sequence), unfortunately, I'm not able to add the second condition to this code and the Web research remained without a solution.
exiftool -sep "||" -G1 -a -s -RegionName -Keywords -ext jpg -overwrite_original -r %1
exiftool -P -overwrite_original -api "Filter=s/^/t:/;s/ /:/g" -addtagsfromfile @ "-keywords-<xmp:RegionName" "-keywords+<xmp:RegionName" -ext jpg -r %1
exiftool -P -overwrite_original -api "Filter=s/^/t:/;s/ /:/g" -addtagsfromfile @ "-subject-<xmp:RegionName" "-subject+<xmp:RegionName" -ext jpg -r %1
exiftool -sep "||" -G1 -a -s -RegionName -Keywords -ext jpg -overwrite_original -r %1
exiftool -sep "||" -G1 -a -s -RegionName -Subject -ext jpg -overwrite_original -r %1
The parameter %1 is the fullpath to a folder.
Thank you for any suggestion,
Bruno
Hi Bruno,
Maybe something like this:
exiftool -if "$xmp:regionname =~ /^.N/ and $subject !~ ${xmp:regionname;tr/ /:/;$_=qq(t:$_)}" "-subject+<${xmp:regionname;tr/ /:/;$_=qq(t:$_)}" ...
(add a similar argument to also copy to Keywords)
- Phil
Thank you Phil, helpful as always... !!
Hi Phil, I've tried it on the image (attached) that shows the following on explore:
C:\Users\Bruno\Desktop\TEST01>exiftool -s -subject "fco_025-IMG_1783.jpg
Subject : a:aN0M:Bruno:Stivicevic, t:aN0M:Daniele:Petralia, t:at0F:VARI5:398, t:at0F:VARI5:452, t:at0M:VARI5::281, t:attivisti:azione:strada, t:cortei, t:foto:attivismo, t:foto:panorama
Only the tag t:aN0M:Daniele:Petralia has the regionname that is: C:\Users\Bruno\Desktop\TEST01>exiftool -s -regionname "fco_025-IMG_1783.jpg
RegionName : aN0M Daniele Petralia
while other tag have no regionname. That situation is frequent in the set of 140 thousands photos.
When i run the proposed code I get this:
C:\Users\Bruno\Desktop\TEST01>exiftool -if "$xmp:regionname =~ /^.N/ and $subject !~ ${xmp:regionname;tr/ /:/;$_=qq(t:$_)}" "-subject+<${xmp:regionname;tr/ /:/;$_=qq(t:$_)}" fco_025-IMG_1783.jpg
1 files failed condition
The desired outcome would be:
Subject : a:aN0M:Bruno:Stivicevic, t:aN0M:Daniele:Petralia, t:attivisti:azione:strada, t:cortei, t:foto:attivismo, t:foto:panorama
where the tags "t:at0F:VARI5:398, t:at0F:VARI5:452, t:at0M:VARI5::281" would be removed, but the tag t:attivisti:azione:strada would be kept.
I presume that my initial explanation was poor and I apologize. I also presume that the task might be undecently complicated as the critical prefix have many variants (the first letter may be a,c,f,g,i,p,s), the second can be t or N, the third 0-9 or X, and the fourth F,M or N; the length is always 4 chars).
Anyhow, there's an alternative: manual elimination through a series of calls such as:
exiftool -subject-="t:at0F:VARI5:398" "E:/AA/EV/2023/20231014,MC1,Pavia,RFG055,(FRAN;META;AVI;0AI0)/fco_025-IMG_1783.jpg"
exiftool -subject-="t:at0F:VARI5:452" "E:/AA/EV/2023/20231014,MC1,Pavia,RFG055,(FRAN;META;AVI;0AI0)/fco_025-IMG_1783.jpg"
exiftool -subject-="t:at0M:VARI5::281" "E:/AA/EV/2023/20231014,MC1,Pavia,RFG055,(FRAN;META;AVI;0AI0)/fco_025-IMG_1783.jpg"
Would require time but if there's no better solution, I'm ready. Thanks again and I apologize again.
Sorry Phil,
I've noticed only now that I confused two distinct tasks: 1- to copy regionname into subject/keywords under specific conditions; 2- to remove from subject/keywords the tags with the specific condition.
Just ignore my previous reply and thanks for your comprehension!