C# using TagLib Sharp - Wrong Rating Number?

1.1k views Asked by At

Hey programming community. So I'm using TagLib Sharp library to fetch the metadata from my .mp3s. Everything is going great with one exception. I can read the rating from my MP3s of they're whole numbers (set my Musicbee). Meaning

Stars
5 = 255
4 = 196
3 = 128
2 = 64
1 = 1
unrated=0

The problem I am running into is I use MusicBee where I can set half star ratings. So the value that I should be getting from my ratings is:

Stars
5 = 255
4.5 = 224
4 = 196
3.5 = 160
3 = 128
2.5 = 96
2 = 64
1.5 = 48
1 = 1
unrated=0

However, this is what TagLib is reading:

5 = 255
4.5 = 0
4 = 196
3.5 = 0
3 = 128
2.5 = 0
2 = 64
1.5 = 0
1 = 1

This is the code that I am using to get the ratings:

TagLib.File file = TagLib.File.Create(fi.FullName);
TagLib.Tag tag = file.GetTag(TagLib.TagTypes.Id3v2);

TagLib.Id3v2.PopularimeterFrame tagInfo = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tag, "Windows Media Player 9 Series", true);

byte rate = tagInfo.Rating;

//This is where I'm storing the value as a string to process it later
id3.Rating = tagInfo.Rating.ToString();

My question is, well, two-fold. Is there another usr that I should/could use instead of "Windows Media Player 9 Series"? OR is there a better way that I should be getting the rating from my mp3s? Should I abandon the half-star ratings of Musicbee?

Also, is there a "help" file on taglib? It seems like EVERYTHING that I can find on it is found here. I don't even know what I'm setting to "true" in my code above.

Thank you for your help in advance!

* Update * This is not an answer just fixing a typo from:

1 = 24   to
1 = 1
2

There are 2 answers

1
Paul W On

When using TagLibSharp, the 2nd argument of TagLib.Id3v2.PopularimeterFrame.Get should be the value of the "Email to user" field of the POPM frame.

This value should be "MusicBee" in your case, and not "Windows Media Player 9 Series".

=> The working code is as follows (tested with real-life MusicBee file)

TagLib.File file = TagLib.File.Create(fi.FullName);
TagLib.Tag tag = file.GetTag(TagLib.TagTypes.Id3v2);

TagLib.Id3v2.PopularimeterFrame tagInfo = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tag, "MusicBee", true);

byte rate = tagInfo.Rating;

NB : MusicBee stores "half-stars" with a slightly different convention than the one you imagined : 54 = 1,5 - 118 = 2,5...

3
PeterCo On

According to the ID3v2(3) specification, the purpose of the frame 4.18 POPM

... is to specify how good an audio file is. Many interesting applications could be found to this frame such as a playlist that features better audiofiles more often than others or it could be used to profile a person's taste and find other 'good' files by comparing people's profiles. The frame is very simple. It contains the email address to the user, one rating byte and a four byte play counter, intended to be increased with one for every time the file is played. The email is a terminated string. The rating is 1-255 where 1 is worst and 255 is best. 0 is unknown. If no personal counter is wanted it may be omitted.

I know that programs like MediaMonkey use this half star ratings, but they are not fully compatible with the specification. The linked MediaMonkey forum thread explains, how they calculate the half stars.

You can also have a look for "RATING MM" in the documentation from Mp3tag. It tells about the various implementations of ratings: http://help.mp3tag.de/main_tags.html

This KODI thread shows how they calculate it:

       Values    Rating
-----------------------

0             0   0
0.5        2-22   1
1      1, 23-31   2
1.5       32-63   3
2         64-95   4
2.5      96-127   5
3       128-159   6
3.5     160-195   7
4       196-223   8
4.5     224-254   9
5           255  10