rbarrois / mpdlcd

A small tool to display MPD status on a lcdproc server
MIT License
31 stars 10 forks source link

Substituded Characters which are not in the Charset of display #7

Closed numer closed 5 years ago

numer commented 11 years ago

I've several mp3's which have non standard US characters in the id3 fields. This leads to display wrong strings in the LCD.

For example if the title field contains "İyileşiyorum" the LCD display will show "yileiyorum". An other example: "Yanlızlık Senfonisi" is going to be "Yanlzlk Senfonisi". As you can see the special characters are ignored during display. One solution would be to substitude these characters with there latin counterpart, like ş to s, ğ to g, ı to i, and İ to I. An other would be to produce the real character, but I don't know yet if this is possible.

The display I use is a HD44780.

Some info can be found here: http://www.ccsinfo.com/forum/viewtopic.php?t=48459

podly commented 10 years ago

I also met this problem. I changed mpdwrapper.py in this way (this is only for polish language):

class MPDClient(utils.AutoRetryCandidate):

    def __init__(self, host='localhost', port='6600', password=None, *args, **kwargs):
        super(MPDClient, self).__init__(*args, **kwargs)
        self._client = mpd.MPDClient()
        self._connected = False
        self.host = host
        self.port = port
        self.password = password

    def _decode_text(self, text):
        # MPD protocol states that all data is UTF-8 encoded.
        # Ref: http://www.musicpd.org/doc/protocol/ch01s02.html
        import string
        text = string.replace(text, 'ą', 'a')
        text = string.replace(text, 'ć', 'c')
        text = string.replace(text, 'ę', 'e')
        text = string.replace(text, 'ń', 'n')
        text = string.replace(text, 'ł', 'l')
        text = string.replace(text, 'ó', 'o')
        text = string.replace(text, 'ś', 's')
        text = string.replace(text, 'ź', 'z')
        text = string.replace(text, 'ż', 'z')

        text = string.replace(text, 'Ą', 'A')
        text = string.replace(text, 'Ć', 'C')
        text = string.replace(text, 'Ę', 'E')
        text = string.replace(text, 'Ł', 'L')
        text = string.replace(text, 'Ń', 'N')
        text = string.replace(text, 'Ó', 'O')
        text = string.replace(text, 'Ś', 'S')
        text = string.replace(text, 'Ź', 'Z')
        text = string.replace(text, 'Ż', 'Z')

        return unicode(text, 'utf8')

    def _decode_text_or_list(self, text_or_list):

but I think, that it should be configurable somehow in configuration file. Of corse, all ID3 Tags have to be in UTF-8.

rbarrois commented 10 years ago

Hi,

The main issue here is that different displays support different charsets, and unicode seems to never have been an issue for LCD builders :/

Basically, depending on your hardware, some chars will be displayed correctly while other won't.

I've written a small test script to check this, could you download this (https://gist.github.com/rbarrois/c8cdf7e688b2a6764a31) and run it? Usage: test.py localhost 13666 [charset]

It will send raw text to your display, bypassing the whole mpdlcd setup. If you could experiment with a couple of charsets and tell me what gets displayed, it would be quite helpful.

I think the HD44780 also supports some alternate character maps (in the LCDD.conf configuration), which would help me a bit.

The solution you suggest would be quite cumbersome to maintain — if the list of interested languages expends too much.

podly commented 10 years ago

I tested it and as I supposed, I had some japanese characters instead of polish. And this is OK, becouse my HD44780 has japanese charset inside. HD44780 displays have small charset in eeprom with basic ASCII characters and additional characters based on market it was made, so it is impossible to have UTF8 HD44780 display. But all HD44780 have also RAM for user-generated chars. And as far as I know, the only way to get this working on all HD44780 displays is to generate special chars on the fly and send them to RAM before displaying them. But i think, that this should be done in lcdproc layer. Thats way I choose to just get rid of special characters.

rbarrois commented 10 years ago

@podly OK, I've been reading through lcdproc source code and understand it better - see commit f856c478abe6695b49da3f6594f361937e4a414a.

Could you try the latest master and let me know if it works for you?

rbarrois commented 5 years ago

Hey there,

This should be fixed with mpdlcd 0.5.x; please reopen the issue if you still have problems!