News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Tag to write Keywords, Subject, and HierarchicalSubject

Started by StarGeek, May 19, 2018, 04:03:03 PM

Previous topic - Next topic

StarGeek

I made a tag so that when you write HierarchicalSubject, it will also write the leaf keyword to IPTC:Keywords and XMP:Subject.  So if you want to write something like "People|Family|John", it will write the full string to HierarchicalSubject and just "John" to IPTC:Keywords and XMP:Subject.  Setting -MyHS= should clear out all three tags.

It won't work with exiftool versions from 10.16 to 10.97, but should work with earlier or later versions.  Testing has been limited because of this, but it seems to work well.

MyHS => {
# Writes string to HierarchicalSubject and leaf keywords to IPTC:Keywords and XMP:Subject.
# Requires exiftool ver 10.13 or earlier, or 10.98 or later
# Ver 1.1
# Added temp variable to avoid random hash(?) based error
Require => 'XMP:HierarchicalSubject',
Writable => 1,
List => 'Bag',
WriteAlso => {
'XMP:HierarchicalSubject' =>'$val',
'IPTC:Keywords' => q{ return undef if not defined $val; my $x = $val; $x=~s/.*(?:^|\|)([^|]*)$/$1/; return $x;},
'XMP:Subject' => q{ return undef if not defined $val; my $x = $val; $x=~s/.*(?:^|\|)([^|]*)$/$1/; return $x;},
},
ValueConv => '$val',
},



Example Output:
C:\>exiftool_10.13.exe -myhs+="People|Family|John" -myhs+="People|Family|Jane" y:\!temp\Test3.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -IPTC :Keywords -XMP:Subject -HierarchicalSubject y:\!temp\Test3.jpg
---- IPTC ----
Keywords                        : John, Jane
---- XMP-lr ----
HierarchicalSubject             : People|Family|John, People|Family|Jane
---- XMP-dc ----
Subject                         : John, Jane


* 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).

StarGeek

I have to say that this tag is working out better than I had hoped.  I was only thinking of writing tags when I started, but didn't realize that it could also remove individual tags with -MyHS-=data.  And setting it to nothing (-MyHS=) will clear all three tags.  This will make management of HierarchicalSubject and the individual keywords much easier.
* 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).

Phil Harvey

Looks great.

I'll be rolling out ExifTool 10.98 in a few days.

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

StarGeek

With more testing on 10.98, I was running into the occasional problem that only the leaf word was being added to HierarchicalSubject.  I suspect it was the fact that you can't depend upon the order of a hash and that I was changing the value of $val.  Now $val is assigned to a temp variable and the regex is performed on that and then returned. 

Original post has been updated.  Now it's time to re-write a whole lot of commands to use this.
* 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).

Phil Harvey

I don't remember what your original code looked like, but I usually do sort keys %HASH to avoid the hash order problem.

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

mnaoumov

I put it inside

Quote'Image::ExifTool::Composite' => {

I tried to use it but I get

QuoteWarning: Sorry, MyHS is not writable
Nothing to do.

it has
Writable => 1

I also tried to change to
Writable => 'string'

But it doesn't help

I am using ExifTool 12.11 on Windows

Please assist

mnaoumov

Nevermind, found it

I had to put it under

%Image::ExifTool::UserDefined::xxx = (

which was not obvious (to me) :)

StarGeek

Quote from: mnaoumov on June 11, 2021, 12:16:54 PM
which was not obvious (to me) :)

Sorry, I'll have to make this easier to work with when I get a chance.  I'm trying to remember if my local copy has a fix that I may not have put into this version.  While I use this a lot, it didn't seem to have generated much interest, so I may not have kept it updated.
* 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).