View Full Version : Artist names and UTF-8

2005-06-28, 14:18
Hi all,

I'm trying to get to the bottom of a UTF-8 problem with SlimScrobbler, and I'd gratefully appreciate the assistance of folks who know perl and the SlimServer internals better than I :)

The problem in a nutshell is that SlimScrobbler munges accented and non-English characters when it passes them up to AudioScrobbler. I've been digging around and found an apparent problem in SlimScrobbler, but I can't get things to work well.

SlimScrobbler gets the track details with a piece of code like:

$ds = Slim::Music::Info::getCurrentDataStore();
$track = $ds->objectForUrl($filename);
$artistName = $track->artist();
$trackTitle = $track->title();

$album = $track->album();
$albumName = $album->title();

(actually it guards against getting back undef for the datastore, track etc. but that's the gist)

Later on, it turns the track, album and artist names into URI-encoded UTF-8. I'm currently doing this with URI::Escape::uri_escape_utf8, but I've tried a couple of different approaches lately.

I'm consistently seeing the track and album names encoded correctly, but the artist name encoded in some incorrect single-byte form (perhaps latin-1, perhaps just the low byte of the Unicode character).

As a test, I constructed an MP3 with artist, title and track all called "Tt". In Unicode, this is:
U+0054 U+00EB U+00A7 U+00C4
and in UTF-8 (as hex):
54 C3 AB C2 A7 74

When I pass the artist name though uri_encode_utf8, I get "T%EB%A7t", which isn't right. When I pass the album and track name through that function, I get "T%C3%AB%C2%A7t", which is correct.

Curiously, when I pass these three values through uri_encode (the non-UTF8'ing version), I get the incorrect version each time. It's as if the artist name is somehow internally marked as already being UTF-8 and so the UTF-8 part of uri_encode_utf8 is being skipped.

I'm at a loss to explain this, partly because I don't really understand how perl handles strings. However, as we get different behaviour for the artist than we do for the track, I suspect that this behaviour is a problem with SlimServer itself? If not, how should I code around this in the SlimScrobbler?

I've demonstrated this difference in behaviour with the v6.1 2005_06_26 build, but I was also seeing it with v6.0. My test track's names all appear correctly both on the player and web interface.

Any assistance greatly appreciated...

2005-06-28, 16:01
iwp wrote:
> $ds = Slim::Music::Info::getCurrentDataStore();
> $track = $ds->objectForUrl($filename);
> $artistName = $track->artist();
> $trackTitle = $track->title();
> $album = $track->album();
> $albumName = $album->title();

I think your problem is relying on the stringification of the artist object.

Try this:
$artist = $track->artist();
$artistName = $artist->name();

2005-06-29, 12:04
Thanks Grotus, works a treat. Didn't realise that artist was coming back as an object...