rbarrois / mpdlcd

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

crash of mpdlcd on some mp3s #8

Closed MikeDK closed 10 years ago

MikeDK commented 10 years ago

I experienced crashes on several mp3s in my media library. The crash always occurred on the same code line, the debug output is following:

DEBUG mpd Calling MPD currentsong()
ERROR mpdlcd.lcdrunner Found exception coercing to Unicode: need string or buffer, list found, exiting.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/lcdrunner.py", line 89, in run
    self.update()
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/utils.py", line 64, in decorated
    return fun(instance, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/lcdrunner.py", line 77, in update
    updated, new_data = hook.handle(self.client, subhooks)
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/mpdhooks.py", line 77, in handle
    new_data = self.fetch(client)
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/mpdhooks.py", line 130, in fetch
    return client.current_song
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/utils.py", line 64, in decorated
    return fun(instance, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/mpdwrapper.py", line 112, in current_song
    song_tags = self._decode_dict(self._client.currentsong())
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/mpdwrapper.py", line 43, in _decode_dict
    (k, self._decode_text(v)) for k, v in data.items())
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/mpdwrapper.py", line 43, in <genexpr>
    (k, self._decode_text(v)) for k, v in data.items())
  File "/usr/local/lib/python2.7/dist-packages/mpdlcd/mpdwrapper.py", line 39, in _decode_text
    return unicode(text, 'utf8')
TypeError: coercing to Unicode: need string or buffer, list found
INFO mpdlcd.lcdrunner Exiting: removing screen MPD

As I am a newbie in python (in fact I never did anything in python ;-) ... I usually code in C/C++), I did some google research, and found that a single change fixes the problem:

in file mpdwrapper.py, line 39, the line with

return unicode(text, 'utf8')

shall be replaced with:

return unicode(str(text), 'utf8')

this will fix the problem ... please review that change and put it into the main rep, if its suitable

regards, Michael

rbarrois commented 10 years ago

Hi,

Unfortunately, the proposed fix might crash fields containing non-ascii chars; here, the issue is that some field returns as a "list", which is unexpected.

I'll look into it.