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.