[SOLVED] UTF8 vs UTF16 Developer Help Requested

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

[SOLVED] UTF8 vs UTF16 Developer Help Requested

Post by Melloware » Sun Nov 15, 2009 10:52 am

Hey MM Fans,

I have been working with MediaMonkey for about 2 years now and I love it. I am currently working on an MM plugin to replace my current iMonkey application. I am almost complete except I have 1 problem left to solve.

Problem: MM3 uses SQLLite and I think it is storing all information in UTF16, however my plugin requires use of only UTF8.

Explanation: Let's take the Artist "Björk" for example. When querying MM database the string value is returned as "Björk" in UTF16/Unicode. I then convert it to UTF8 and it becomes "Björk". This renders properly as "Björk" because the application I am speaking to understands UTF8. However, when they click on that artist in the UI it send back to my plugin which artist was selected in URL encoded format such as :

Bj%C3%B6rk

instead of:

Bj%F6rk

So when I get this value as a URL decoded string I am trying to do:

Code: Select all

SELECT * Songs.AlbumArtist = 'Björk' ORDER BY Songs.Album, Songs.TrackNumber 
instead of the proper:

Code: Select all

SELECT * Songs.AlbumArtist = 'Björk' ORDER BY Songs.Album, Songs.TrackNumber 
I have tried everything to convert "Bj%C3%B6rk" back to the proper UTF16 version that MM needs but nothing seems to work. So I am asking all developers out there....does anyone have any suggestions? Any help would be appreciated.

Thanks,
Mello
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: [SOLVED] UTF8 vs UTF16 Developer Help Requested

Post by Melloware » Mon Nov 16, 2009 4:30 pm

For those of you that care here is my code to fix this problem.

C#:

Code: Select all

string artist = "Béla Fleck";
Encoding ISO_8859_1 = .Encoding.GetEncoding("iso-8859-1");
// Convert the bytes from ISO_8859_1 to utf-8:
byte[] isoBytes = ISO_8859_1.GetBytes(artist );
byte[] utf8Bytes = System.Text.Encoding.Convert(ISO_8859_1, Encoding.UTF8, isoBytes);
string utf8 = ISO_8859_1.GetString(utf8Bytes);
this will give me... Béla Fleck = Béla Fleck

I just store a map of the ISO_8859_1 and look them up in a Hashmap to get the MM UTF16 correct value to use in the query.
Last edited by Melloware on Mon Nov 16, 2009 7:30 pm, edited 1 time in total.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

m_bojangles
Posts: 98
Joined: Fri Jun 11, 2004 8:22 pm

Re: [SOLVED] UTF8 vs UTF16 Developer Help Requested

Post by m_bojangles » Mon Nov 16, 2009 6:24 pm

Sweet! Does this mean the new MM client app for iPhone is just around the corner?

Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: [SOLVED] UTF8 vs UTF16 Developer Help Requested

Post by Melloware » Mon Nov 16, 2009 6:46 pm

m_bojangles wrote:Sweet! Does this mean the new MM client app for iPhone is just around the corner?
Yep. This was the last "bug" I had to work out. The artist list would render on the iPhone/iPod OK but then when you clicked on an artist it wouldn't match up and say "no albums found". But this fixed that!

It should be within the week. :)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: [SOLVED] UTF8 vs UTF16 Developer Help Requested

Post by Bex » Mon Nov 16, 2009 8:28 pm

Glad you solved the issue!
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Post Reply