ExifTool Forum

ExifTool => Developers => Topic started by: Joanna Carter on July 11, 2021, 05:06:27 AM

Title: Advice on reading and writing legacy star ratings
Post by: Joanna Carter on July 11, 2021, 05:06:27 AM
Hi folks

I am still struggling with how best to cater for the range of possible tags I am likely to encounter when working with star ratings. So far, I have identified
Not to mention the possibility of legacy Windows tags as well.

Does anyone have any "firm and fast" guidance as to the best strategy?

At present I am leaning towards reading all available tags and using the most recent available, then on re-writing, ensuring that xmp-rating is always written.

But as to what to do with the legacy tags, I am still undecided. I see two main options
Anyone fancy an argument?  ;)
Title: Re: Advice on reading and writing legacy star ratings
Post by: StarGeek on July 11, 2021, 11:38:17 AM
Quote from: Joanna Carter on July 11, 2021, 05:06:27 AM
I am still struggling with how best to cater for the range of possible tags I am likely to encounter when working with star ratings. So far, I have identified

  • the old -exif:rating tag
  • the (preferred) -xmp:rating tag
  • the -xmp-iptcext:rating tag
  • the -XAttrMDItemStarRating tag
Not to mention the possibility of legacy Windows tags as well.

I would advise against XMP-iptcExt:Rating as it isn't a simple rating for the image, it's a structured tag (https://exiftool.org/TagNames/XMP.html#Rating) which includes a second structured tag (https://exiftool.org/TagNames/XMP.html#LocationDetails), for a total of 17 sub-tags.  And none of them seem applicable to rating the image itself (RatingRegionCityRatingRegionGPSLatitude? What does rating region GPSLatitude even mean?).  They are also not included in the IPTC Photo Metadata Standard 2019.1 (https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata).  To be honest, I'm not sure what the use of that structure is ATM, though I'm curious and will now have to spend the next couple hours Googling it :D

The Rating tag used in the IPTC standard is XMP-xmp:Rating (https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata#image-rating).  In most cases on that page, you can take the name listed in the "XMP Specs" row, prefix "XMP-", and you will have the exiftool name for the tag.  The major exception would be ones that list "Data type: * structure", as those would be structured data.

Missing is EXIF:RatingPercent, XMP-xmp:RatingPercent, and XMP-microsoft:RatingPercent.  The first two are marked as Avoid by exiftool.  Windows will set EXIF:RatingPercent and XMP-microsoft:RatingPercent, as well as EXIF:Rating and XMP-xmp:Rating from the Properties window (see Windows Metadata (https://exiftool.org/forum/index.php?topic=6591.msg32875#msg32875)).  I have no idea if XMP-xmp:RatingPercent is used by anything.

QuoteDoes anyone have any "firm and fast" guidance as to the best strategy?

While the Metadata Working Group appears to be defunct, it's Guidelines For Handling Image Metadata (https://web.archive.org/web/20180919181934/http://www.metadataworkinggroup.org/pdf/mwg_guidance.pdf) is still probably the best standard for reconciling data across different groups. See section 4.2.3 "Metadata reconciliation guidance" for details.

QuoteBut as to what to do with the legacy tags, I am still undecided. I see two main options

See section 3.1.2 "Changer" of the MWG guide.  The basic guidelines it gives are
QuoteThe rules for an application in the Changer role are:
  • Deletion of metadata MUST only be done with specific intent.
  • It SHOULD obey rules for Consumer applications when reading metadata.
  • It SHOULD keep all forms of metadata it modifies in sync with one another.

Also remember, when writing to the base tag name, exiftool will update all tags with the same name.  You can use that to your advantage.  For example, you could write
-Rating=5 -XMP-xmp:Rating=5
and exiftool will write EXIF:Rating if it didn't exist, updated any other Rating tags in the file, and force a write of -XMP-xmp:Rating.  If you want to be even more exacting, you could use
-wm w -Rating=5 -execute -XMP-xmp:Rating=5
The -wm (-writeMode) option (https://exiftool.org/exiftool_pod.html#wm-MODE--writeMode) with the w parameter would update all existing Rating tags, even ones that you normally wouldn't think of (XMP-acdsee:Rating, for example) without creating any new ones and then explicitly write the XMP-xmp:Rating.  It would have the disadvantage of requiring more processing, as it is performing two separate operations on the file.
Title: Re: Advice on reading and writing legacy star ratings
Post by: Joanna Carter on July 13, 2021, 08:47:40 AM
Thank you for your insights
I tried you idea of the -writemode tag and found that I can actually use it as a single command by specifying both the w and c parameters.

So I get

exiftool -wm wc -rating=4 filename

which seems to write the xmp:rating tag and change any existing ones at the same time. Which is pretty much what I was hoping for.
Title: Re: Advice on reading and writing legacy star ratings
Post by: Phil Harvey on July 13, 2021, 08:55:38 AM
-wm wc will only write/create xmp:rating if XMP already exists in the file.

- Phil
Title: Re: Advice on reading and writing legacy star ratings
Post by: StarGeek on July 13, 2021, 10:58:50 AM
Quote from: Joanna Carter on July 13, 2021, 08:47:40 AM
I shall use -Rating to read since this defaults to exif:rating if it can't find xmp:rating

Actually it defaults to XMP-xmp:RatingEXIF:Rating is marked as Avoid and will not be written to unless explicitly set.  I did not catch that in my first post.

As Phil said, with -wm wc, some other XMP tag has to exist in the file for XMP-xmp:Rating to be written.  This is also true of EXIF:Rating.  If the EXIF group doesn't exist, then you can't write any EXIF tags with the -wm wc option.  An unlikely situation with images directly from a camera, but quite possible with images downloaded from social media.

C:\>exiftool -P -overwrite_original -exif:all= y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -P -overwrite_original -wm wc -exif:rating=4 y:\!temp\Test4.jpg
    0 image files updated
    1 image files unchanged


You will probably want to use this without the -wm option
-EXIF:Rating=4 -Rating=4
This will explicitly set the EXIF:Rating, create the XMP-xmp:Rating, which is the default tag for just -Rating, and update any other Rating tag.

Title: Re: Advice on reading and writing legacy star ratings
Post by: Joanna Carter on July 13, 2021, 01:22:13 PM
I start with an "empty" file then add just the -exif:rating tag

exiftool -exif:rating=1 filename

Which reads back as


exiftool -rating filename       
Rating                          : 1
exiftool -exif:rating filename
Rating                          : 1


Then run the "magic" command

exiftool -wm wc -rating=4 filename

So now I get exactly what I wanted


exiftool -rating filename         
Rating                          : 4
exiftool -exif:rating filename
Rating                          : 4
exiftool -xmp:rating filename
Rating                          : 4


So it seems that -xmp:rating does get written, even though it didn't exist.

Or, Phil, did you mean that it wouldn't if there as absolutely no XMP tags at all? In which case, surely that is going to be rare?
Title: Re: Advice on reading and writing legacy star ratings
Post by: StarGeek on July 13, 2021, 02:04:57 PM
Quote from: Joanna Carter on July 13, 2021, 01:22:13 PM
Or, Phil, did you mean that it wouldn't if there as absolutely no XMP tags at all?

Yes, if there are no XMP tags or no EXIF tags (see my example above and new example below), then because -wm wc will not create new groups i.e. the g option, then the tag will not be created.

Example:
C:\>exiftool -P -overwrite_original -all= y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -P -overwrite_original -wm wc -exif:rating=1 -xmp:rating=2 -rating=3 y:\!temp\Test4.jpg
    0 image files updated
    1 image files unchanged

C:\>exiftool -g1 -a -s -rating y:\!temp\Test4.jpg

C:\>


QuoteIn which case, surely that is going to be rare?

No XMP tags is would be the default.  Most cameras will not have XMP data straight from the camera.  It's usually only EXIF.  Some camera phones will have region data for faces, which would be XMP and allow creation of more XMP tags, but otherwise very rare.
Title: Re: Advice on reading and writing legacy star ratings
Post by: Joanna Carter on July 13, 2021, 04:18:36 PM
Hmmm

In that light of that, I wrote

exiftool -exif:all= filename
exiftool -xmp:all= filename

followed by

exiftool -exif:rating=1 filename

Which gave me


exiftool -exif:rating filename 
Rating                          : 1
exiftool -rating filename   
Rating                          : 1


Then I wrote

exiftool -wm wcg -rating=4 filename

Which gave me

exiftool -exif:rating filename     
Rating                          : 4
exiftool -rating filename         
Rating                          : 4
exiftool -xmp:rating filename
Rating                          : 4


Surely, writing

exiftool -exif:all= filename
exiftool -xmp:all= filename

would have deleted both groups. Or am I still not getting it?
Title: Re: Advice on reading and writing legacy star ratings
Post by: StarGeek on July 13, 2021, 05:12:24 PM
You added the g for creating new groups.  -wm wcg is the default that exiftool writes at.

See the -wm (-writeMode) option (https://exiftool.org/exiftool_pod.html#wm-MODE--writeMode)
Title: Re: Advice on reading and writing legacy star ratings
Post by: Joanna Carter on July 14, 2021, 04:24:54 AM
Thanks. I have read the docs, but one thing still puzzles me. Why is –wcg described as the "default" when entering exiftool -wm -rating=2 filename returns Invalid argument for -wm option ?
Title: Re: Advice on reading and writing legacy star ratings
Post by: Joanna Carter on July 14, 2021, 05:45:50 AM
Now I have to get down to integrating this command into my macOS app.

The list of arguments used to be


"-preserve"
"-ignoreMinorErrors"
"-overwrite_original_in_place"
"-xmp:rating=4"
"/Users/joannacarter/Pictures/Test.jpg"


But I think now becomes


"-preserve"
"-ignoreMinorErrors"
"-overwrite_original_in_place"
"-wm wcg -rating=4"
"/Users/joannacarter/Pictures/Test.jpg"


This should translate to exiftool -preserve -ignoreMinorErrors -overwrite_original_in_place -wm wcg -rating=4 /Users/joannacarter/Pictures/Test.jpg

But this is giving me a response of

Warning: Tag 'wm' is not defined
Nothing to do.


And ExifTool in Terminal (unsurprisingly) shows that neither -exif:rating nor -xmp:rating have been updated

And if I separate out the -wm... argument into two separate arguments


"-preserve"
"-ignoreMinorErrors"
"-overwrite_original_in_place"
"-wm wcg"
"-rating=4"
"/Users/joannacarter/Pictures/Test.jpg"


That then gives me a response of

Invalid TAG name: "wm wcg"
Ignored superfluous tag name or invalid option: -wm wcg


But, checking with ExifTool in Terminal, both -exif:rating and -xmp:rating have been correctly updated

So, my question is, why the error report?
Title: Re: Advice on reading and writing legacy star ratings
Post by: Joanna Carter on July 14, 2021, 06:10:34 AM
Replying to self to leave the answer to this who are searching for the same issue

-wm and cwg have to be specified as two separate arguments


"-preserve"
"-ignoreMinorErrors"
"-overwrite_original_in_place"
"-wm"
"cwg"
"-rating=4"
"/Users/joannacarter/Pictures/Test.jpg"


Thanks to one and all for the rubber duck consulting
Title: Re: Advice on reading and writing legacy star ratings
Post by: Phil Harvey on July 14, 2021, 06:24:17 AM
The -wm cwg option is not necessary since this is the default behaviour of ExifTool.

- Phil
Title: Re: Advice on reading and writing legacy star ratings
Post by: Joanna Carter on July 14, 2021, 07:20:10 AM
Quote
The -wm cwg option is not necessary since this is the default behaviour of ExifTool.

Ah, so that's what it means  ::)

And there was I going to all the trouble to modify my Swift wrapper to accommodate it. never mind, it will come in useful for times when I don't need all three options

Out of interest, here's what the calling code now looks like


    let ratingsArguments: [ExifCommand.Argument] = [.writeMode([.createNewTags, .writeExistingTags, .createNewGroups]), .writeRating(rating)]