ExifTool Forum

ExifTool => Newbies => Topic started by: rcgordon on January 20, 2017, 08:27:01 PM

Title: Syntax to Add or Change Rating or Label
Post by: rcgordon on January 20, 2017, 08:27:01 PM
Hi,

I'm confused about the syntax for a command that would do the following:

I want to delete the rating and label (as set by Adobe Bridge) for a group of images, without changing the modification date.

Please clarify also how to set the rating to a number and set the label to a value (say, "Approved"), where either a prior value does or does not exist.

Thank you.
Title: Re: Syntax to Add or Change Rating or Label
Post by: StarGeek on January 20, 2017, 09:25:55 PM
I haven't tested Adobe Bridge yet, but you can find some tag information from Lightroom 4.4 here (https://exiftool.org/forum/index.php/topic,6959.0.html). 

LR uses xmp:rating for the rating, so to clear that your command would include -xmp:rating= or to clear rating data that might be in the EXIF block as well, -rating=

To clear the label, use -label=

You can add -P to prevent the system time stamps from changing and the ModifyDate tag isn't automatically altered by exiftool, you have to do it manually.

To set rating and label, you simple set them equal to the value you want.  For example, -label="Approved" to set the label to Approved.  You may have to play with what values rating sets and reads.  I haven't tested to see if it's a 0-5 scale or 0-100 scale. 

See FAQ 3 (http://www.exiftool.org/faq.html#Q3) for help in figuring what Bridge reads and writes.

Bridge is on my list of apps to test and chart like I did for LR, but I haven't gotten around to it yet.
Title: Re: Syntax to Add or Change Rating or Label
Post by: rcgordon on January 20, 2017, 09:55:50 PM
Thanks. It appears that both ratings and labels are numerically (0-5), and labels are strings:

exiftool -P rating=3 -label="Approved" FILENAME

...sets the rating to 3 stars and the label to "Approved" without affecting the mod date. Perfect! Thanks.
Title: Re: Syntax to Add or Change Rating or Label
Post by: knox on October 13, 2020, 01:19:58 AM
I'm trying to set a Windows Explorer rating of a MP4 file. "-rating=3" isn't working for me only on JPG files. Does anybody know how to set the rating of a MP4 file?
Title: Re: Syntax to Add or Change Rating or Label
Post by: StarGeek on October 13, 2020, 02:41:36 AM
The rating displayed under Properties->Details tab is held in the Microsoft:SharedUserRating tag.  Exiftool does not have the ability to edit this tag.  In fact, there is almost no software that I've been able to find that can edit the Microsoft video tags (https://exiftool.org/TagNames/Microsoft.html#Xtra).  One notable exception is MP3Tag (https://www.mp3tag.de/) which, despite its name, can edit tags in MP4 files.  I don't know if it can edit the Microsoft:SharedUserRating tag, but you might check it out.
Title: Re: Syntax to Add or Change Rating or Label
Post by: knox on October 13, 2020, 05:18:55 AM
Thank you for your answer. I tried MP3Tag and the 3 rating types which it supports but none of them worked for me :-(

Is there a chance that ExifTool will support this MS tag in the future? A command line tool is what I need.
Title: Re: Syntax to Add or Change Rating or Label
Post by: Phil Harvey on October 13, 2020, 08:21:23 AM
This certainly isn't something that will be added in the near future, especially since I haven't had any other requests for this feature.

- Phil
Title: Re: Syntax to Add or Change Rating or Label
Post by: TimR on September 22, 2021, 08:35:51 AM
Late to the party I know, but Windows Live Photo Gallery (WLPG) can write to the Microsoft:SharedUserRating tag for MOV and MP4 files. It isn't command line though. It can also write captions ItemList:Title to these files. I use both, as then I can use Windows Search (with its indexing).

And Phil, if you ever did get around to making exiftool able to write to the Microsoft:SharedUserRating tag, that would be two of us who would use it!

PS Thanks for the exiftool, it's excellent.
Title: Reading and Writing Microsoft Windows Video Rating
Post by: Jean-Pierre on February 04, 2023, 03:53:36 PM
It seems that writing to   Microsoft:SharedUserRating   is working now (in order to set star-ratings to a mp4-video by exiftool).

You can enter the values equivalent to the photo rating in  XMP-microsoft:RatingPercent  :
#https://exiftool.org/forum/index.php?topic=6591.msg32875#msg32875
'Reading' and 'writing' depends on which view you take. So I rephrased it a little:

When reading the star rating from windows into the tag  Microsoft:SharedUserRating:
0 stars = clears tag content
1 star  =  1
2 stars = 25
3 stars = 50
4 stars = 75
5 stars = 99
When writing to the tag the following star number is the result in windows:
no tag or 0 (or a negative value) = 0 star
 1-12 = 1 star
13-37 = 2 stars
38-62 = 3 stars
63-87 = 4 stars
88-100+ = 5 stars


Is there a smart conversion available in  ExifTool  like the one for photos using the tag
MWG:Rating   to convert between   XMP:Rating  (scale from 0 to 5) and 
XMP-microsoft:RatingPercent   (scale from 0 to 100)   ?


The goal would be to use one single 'rating' input tag, no matter whether it finally goes into a video or a photo...



Title: Re: Syntax to Add or Change Rating or Label
Post by: Phil Harvey on February 04, 2023, 05:14:48 PM
You could do something like this:

exiftool -userparam myrating=XX "-xmp:rating<${myrating;$_=int(($_+37)/25)}" "-xmp:ratingpercent<$myrating" -fast5 FILE

Here, "XX" is a rating from 0 to 100, and this is converted in to the range 1-5 when writing XMP-xmp:Rating.  I've added -fast5 to the command because we don't actually have to read any tags from the file (we're only copying from user-defined parameters).

You could do a similar thing for SharedUserRating.

- Phil
Title: Re: Syntax to Add or Change Rating or Label
Post by: Jean-Pierre on February 05, 2023, 05:08:43 PM
Thanks, Phil, for the syntax for doing calculations.
That helps. And I can do the conversion in both directions easily typing in the rating by hand.


But I cannot read the content of the variable  Quicktime:Microsoft:SharedUserRating  into the userparameter  myrating  for automatic conversion. 
-userparam myrating<SharedUserRating  does not work, it only accepts  -userparam myrating=number (or string)
It seems like it is a constant parameter, and not a variable tag  (nomen est omen) .

Or do I just have a newbie-problem with the syntax?
Title: Re: Syntax to Add or Change Rating or Label
Post by: Phil Harvey on February 05, 2023, 06:23:39 PM
If you are pulling from a real tag, use that tag name instead of the user-defined parameter.  I chose a user-defined parameter because I thought you wanted to specify the rating yourself.

exiftool "-xmp:rating<${SharedUserRating;$_=int(($_+37)/25)}" "-xmp:ratingpercent<$SharedUserRating " FILE

I don't have time to think about the math, but hopefully you get the idea.

- Phil
Title: Re: Syntax to Add or Change Rating or Label
Post by: Jean-Pierre on August 04, 2023, 02:12:11 AM
Rating Conversion Summary
after having done more "thinking about the math..."  ;) I want to bring it all together in one place:

Conversion table between different rating scales:

XMP-generic    XMP:rating  or  # of stars    0        1        2        3        4        5
MS - photo    XMP:XMP-microsoft:RatingPercent    0        1      25      50      75      99
MS - video    Quicktime:Microsoft:sharedUserRating    0        1      25      50      75      99
    Microsoft's represented range    0%    1..12%  13..37%  38..62%  63..87%  88..100%


Exact (single line) conversion commands, using some non-linear math formulas:

1) XMP to Microsoft
from    xmp:rating                (0 through 5, equivalent to 0 through 5 stars) 
to        xmp:ratingPercent    (0 ... 99, nonlinear scale !)  :
a) Photo:
   Exiftool -xmp:ratingPercent<${xmp:rating;$_=int((0.8+($_-0.99)*24.7)*$_/($_+0.005))} FILENAME
If  xmp:rating  is not set, the conversion leaves  xmp:ratingPercent  unchanged.
b) Video:
Here is the equivalent conversion for rating of videos with a Quicktime:Microsoft tag
(same formula, just different tag names; for easy copying):
   Exiftool -ext mp4 -Quicktime:Microsoft:sharedUserRating<${xmp:rating;$_=int((0.8+($_-0.99)*24.7)*$_/($_+0.005))} FILENAME

2) Microsoft to XMP
from    xmp:ratingPercent      (0 ... 100, nonlinear scale !) 
to        xmp:rating                  (0 through 5, equivalent to 0 through 5 stars) :
a) Photo:
   Exiftool -xmp:rating<${xmp:ratingPercent;$_=int((1.54+($_-1)/25)*$_/($_+0.005))} FILENAME
This conversion not only holds for the specific table values, but also for the entire represented range of Microsoft Ratings with an accuracy of 1%.
If  xmp:ratingPercent  is not set, the conversion leaves  xmp:rating  unchanged.
b) Video:
The same for rating of videos results in
(same formula, just different tag names; for easy copying):
   Exiftool -ext mp4 -xmp:rating<${Quicktime:Microsoft:sharedUserRating;$_=int((1.54+($_-1)/25)*$_/($_+0.005))} FILENAME

All four conversion commands have been checked for proper operation in a tool for modifying star ratings of files which had been previously rated by Microsoft File Explorer (or several other tools using the same tags), reading in Microsoft's ratings before modification, and writing out to Microsoft's rating after modification.


Alternative approach
(might be faster, but needs 2 command lines per conversion):
All four conversions contain the multiplier  *$_/($_+0.005)  -  which evaluates (after rounding) to 1 for any integer input number $_ except 0, where it evaluates to 0. It has the only purpose to support the zero to zero conversion; all the other input values are converted already correctly by the rest of the formula. It has not been checked, whether leaving out this multiplier and adding a conditional handling of the zero point would do the same job at a somehow faster speed (might be of interest for bulk conversion tasks).
The additional command lines for this conditional handling would have the following syntax, respectively,
XMP to Microsoft
a) Photo:   Exiftool -if $xmp:rating eq 0 -xmp:ratingPercent=0 FILENAME
b) Video:   Exiftool -ext mp4 -if $xmp:rating eq 0 -Quicktime:Microsoft:sharedUserRating=0 FILENAME
Or for the inverse conversion:
Microsoft to XMP
a) Photo:   Exiftool -if $xmp:ratingPercent eq 0 -xmp:rating=0 FILENAME
b) Video:   Exiftool -ext mp4 -if $Quicktime:Microsoft:sharedUserRating eq 0 -xmp:rating=0 FILENAME

For handling one file at the time, the single line conversion turned out to be appropriate.


Title: Re: Syntax to Add or Change Rating or Label
Post by: Joanna Carter on August 11, 2023, 08:48:01 AM
Quote from: StarGeek on January 20, 2017, 09:25:55 PMFor example, -label="Approved" to set the label to Approved

Not forgetting that, if any other DAM software uses colour names, these have to be in the locale of the machine they are expected to be read and written on.

So, if a DAM uses colour names like Red, Yellow and Green, on an English language locale, a French locale might not colour the label because it would be expecting Rouge, Jaune and Vert.

Don't forget the Label tag is purely text and colour is only inferred depending on the software.