Column Script to Show POPM Ratings as "Stars"


#1

Hello folks,

The latest version of Winamp (5.61) adds an option to store Mp3 ratings in the POPM tag in files. Since Mp3tag supports this field, I decided to add a custom column that would display the ratings properly. I wrote a script, but it turned into a monster (453 characters!). Perhaps someone here can help me simplify the logic in this and other scripts that use regular expressions to compare values.

The attached screen shot shows the raw data in the center and the script output on the left. The raw column is needed only to verify script output during testing. Winamp uses the five rating values shown in the screen shot. I used regular expressions to capture those values and additional logic to determine the correct number of "stars" to show. To make the script easier to read, the six components are first shown here on separate lines:

$if($isdigit($regexp(%popularimeter%,'(?:.+\|)(\d{1,3})(?:\|\d+)',$1)),[next line],)

$ifgreater($regexp(%popularimeter%,'(?:.+|)(\d{1,3})(?:|\d+)',$1),196,●●●●●,[next line])
$ifgreater($regexp(%popularimeter%,'(?:.+|)(\d{1,3})(?:|\d+)',$1),128,●●●●,[next line])
$ifgreater($regexp(%popularimeter%,'(?:.+|)(\d{1,3})(?:|\d+)',$1),64,●●●,[next line])
$ifgreater($regexp(%popularimeter%,'(?:.+|)(\d{1,3})(?:|\d+)',$1),1,●●,[next line])
$ifgreater($regexp(%popularimeter%,'(?:.+|)(\d{1,3})(?:|\d+)',$1),0,●,)

In the actual script, each "[next line]" is replaced by the line below it. The working script looks like this and goes in the Value box of the Rating column:

$if($isdigit($regexp(%popularimeter%,'(?:.+\|)(\d{1,3})(?:\|\d+)',$1)),$ifgreater($regexp(%popularimeter%,'(?:.+\|)(\d{1,3})(?:\|\d+)',$1),196,●●●●●,$ifgreater($regexp(%popularimeter%,'(?:.+\|)(\d{1,3})(?:\|\d+)',$1),128,●●●●,$ifgreater($regexp(%popularimeter%,'(?:.+\|)(\d{1,3})(?:\|\d+)',$1),64,●●●,$ifgreater($regexp(%popularimeter%,'(?:.+\|)(\d{1,3})(?:\|\d+)',$1),1,●●,$ifgreater($regexp(%popularimeter%,'(?:.+\|)(\d{1,3})(?:\|\d+)',$1),0,●,))))),)

Translation: a regular expression captures one to three digits from between pipe symbols (|). $isdigit is used to exit the script if no digits are found (otherwise, an empty POPM field would be evaluated five times). If digits are found, their value is compared to one of five threshold numbers by using nested $ifgreater functions. The threshold numbers are the standard Winamp ratings. If the captured number is above the threshold, then $ifgreater returns the appropriate number of stars. If the captured number is the same or smaller, then the next $ifgreater function checks for the next lower threshold, and so on, until the value is zero. If no number is found, nothing is displayed.

It seems that true stars are not available, but black circles do the job. The character is Unicode U+25CF, which is supported by system fonts "Segoe UI" and "Microsoft Sans Serif". With other fonts, you might need to choose a different character. The new column is read-only, but you can add a raw POPM field to your tag panel for editing.

My script works, but is there is a simpler way? What bothers me is that the regular expression must be matched up to five times per tag, even though the returned value is of course the same every time. That is inefficient. It would be nice if the returned value of the first $regexp could be reused in subsequent logic, but in my tests $1 would not work that way.



Rating and PopMeter as column in Mp3tag listview
[AF] Popularimeter Tag Fails in 2.48c
Traktor rating sync idv3 Tag
How may I import MediaMonkey ratings?
#2

Doug, do you know this post?
Bewertung WinAmp in rating wmp

Put this Formatstring into the Value edit field of a column definition dialog, leave the Field edit field empty ...

$repeat('*',$if($eql($regexp(%POPULARIMETER%,'^rating@winamp\.com\|(\d{3})\|.+$','$1'),255),5,$if($eql($regexp(%POPULARIMETER%,'^rating@winamp\.com\|(\d{3})\|.+$','$1'),196),4,$if($eql($regexp(%POPULARIMETER%,'^rating@winamp\.com\|(\d{3})\|.+$','$1'),128),3,$if($eql($regexp(%POPULARIMETER%,'^rating@winamp\.com\|(\d{2})\|.+$','$1'),64),2,$if($eql($regexp(%POPULARIMETER%,'^rating@winamp\.com\|(\d{1})\|.+$','$1'),1),1,%RATING WMP%))))))

... and you will get stars for numbers ...

1=*
64=**
128=***
196=****
255=*****

DD.20110401.2353.CEST


#3

★ character for stars does not work in all UI elements in the program but it works in the columns view.
You can also get it with $char(9733)


#4

DetlevD, somehow I missed those examples. I like the way that you use $repeat to show the %RATING WMP% value when POPM is empty. That is clever. I have integrated that and other elements of your example into my script.

Thanks for a prompt and useful response!

Thank you, Dano. You inspired me to look for others and I found:

☆ white star: $char(9734)
✰ shadowed white star: $char(10032)

Here is my revised script (now down to 370 characters):

$repeat($char(10032),$if2($ifgreater($regexp(%popularimeter%,'^.+\|(\d{1,3})\|\d+',$1),196,5,$ifgreater($regexp(%popularimeter%,'^.+\|(\d{1,3})\|\d+',$1),128,4,$ifgreater($regexp(%popularimeter%,'^.+\|(\d{1,3})\|\d+',$1),64,3,$ifgreater($regexp(%popularimeter%,'^.+\|(\d{1,2})\|\d+',$1),1,2,$ifgreater($regexp(%popularimeter%,'^.+\|(\d)\|\d+',$1),0,1,))))),%RATING WMP%))

My reason for using $ifgreater is that it allows stars to be shown for any value (whatever number a player may assign). In other words, my script is not limited to the Winamp system. Of course, with ratings added by other players, the number of stars displayed may not be correct. I don't care about that. Stars showing for newly-imported files are simply an alert for me to remove those ratings.

Regards to you both,

Doug


#5
QUOTE ( @ Apr 3 2011, 00:04) <{POST_SNAPBACK}>
...

☆ white star: $char(9734)
✰ shadowed white star: $char(10032)


I see 'sqare' characters.
What screen font do you use?

DD.20110403.0824.CEST


#6

Sorry, DetlevD, but I don't know how to find out for sure which screen font Mp3tag is using in columns.

I am running Vista SP2 in Windows Classic mode with "Microsoft Sans Serif" as my default font for applications ("Segoe UI" is the Vista-supplied default). According to Windows Character Map, neither of those fonts shows the white star glyphs mentioned in this thread. However, a tool found on this page says they are included:

http://www.fileformat.info/info/unicode/ch...fontsupport.htm

You can click on the "Local Font List" tool to see which fonts on your PC include the "shadowed white star" character.

What complicates matters is that Windows and browsers may use substitute fonts in some situations. And I don't know if the tool above is reliable!


#7

Doug, thank you for answering.

I am on Win XP in Windows Classic mode with "Tahoma".
Tahoma seems to be not a full unicode aware font.
It is not a big deal for me.

I simply was wondering about the fact that the Mp3tag list view cannot display all unicode characters (... depending on the choosen system font ???).

DD.20110403.1720.CEST


#8

UPDATE: As of v. 2.48c, Mp3Tag added the field %rating winamp% for MP3 files, which means that the %popularimeter% field no longer works on the tag panel. Therefore, I have modifed my script as follows to work with all POPM formats in v. 2.48c:

With line breaks added for clarity:

$if(%rating winamp%,$repeat($char(10032),%rating winamp%),

$if(%rating wmp%,$repeat($char(9733),%rating wmp%),
$if(%rating mm%,$repeat($char(10026),%rating mm%),$repeat($char(10061),
$if2($ifgreater($regexp(%popularimeter%,'^.+|(\d{1,3})|\d+',$1),196,5,
$ifgreater($regexp(%popularimeter%,'^.+|(\d{1,3})|\d+',$1),128,4,
$ifgreater($regexp(%popularimeter%,'^.+|(\d{1,3})|\d+',$1),64,3,
$ifgreater($regexp(%popularimeter%,'^.+|(\d{1,2})|\d+',$1),1,2,
$ifgreater($regexp(%popularimeter%,'^.+|(\d)|\d+',$1),0,1,))))),0)))))

Without line breaks:

$if(%rating winamp%,$repeat($char(10032),%rating winamp%),$if(%rating wmp%,$repeat($char(9733),%rating wmp%),$if(%rating mm%,$repeat($char(10026),%rating mm%),$repeat($char(10061),$if2($ifgreater($regexp(%popularimeter%,'^.+\|(\d{1,3})\|\d+',$1),196,5,$ifgreater($regexp(%popularimeter%,'^.+\|(\d{1,3})\|\d+',$1),128,4,$ifgreater($regexp(%popularimeter%,'^.+\|(\d{1,3})\|\d+',$1),64,3,$ifgreater($regexp(%popularimeter%,'^.+\|(\d{1,2})\|\d+',$1),1,2,$ifgreater($regexp(%popularimeter%,'^.+\|(\d)\|\d+',$1),0,1,))))),0)))))

Four different Unicode glyphs are used to distinguish the rating source. These work for me on Vista but may not be available on all versions of Windows. Of course, you can use different characters.

Sorting by the ratings column is a bit slow with such a long script. The sort is not always as expected but within each of the four types, sorting works fine. In the Customize columns dialog, I do not use the Numeric option and I sort on field %rating winamp%. That puts all Winamp ratings at the top of a descending sort.

Thanks to Dano, DetlevD, and the others here who have tutored me on scripting!

Doug Mackie