2014-08-30, 16:22
So, I've been messing with the CULRC lyrics script to try and get it to support streaming radio better. I've got to the point where it correctly identifies the stream and grabs the artist/title data via json. The problem I have is that there is a routine that gets called later to de-accent the strings, and this fails with a "TypeError: decoding Unicode is not supported". I don't want to mess with the rest of the script, just the bit that parses the stream info.
The code I'm using to get the stream info is as follows
Although this works, the script fails later with the aforementioned error at this routine
Relevant error from my debug log is
Some help with this would be really appreciated.
Thanks.
The code I'm using to get the stream info is as follows
PHP Code:
if not xbmc.getInfoLabel("MusicPlayer.TimeRemaining") and song.title == "":
my_json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": [ "title"], "playerid": '"0"' }, "id": "AudioGetItem"}')
my_json_response=simplejson.loads(my_json_query)
if my_json_response.has_key('result') and (my_json_response['result'] != None) and (my_json_response['result'].has_key('item')):
song.title = my_json_response['result']['item']['title']
sep = song.title.find("-")
if sep > 1:
song.artist = song.title[:sep - 1].strip()
song.title = song.title[sep + 1:].strip()
log ('Artist : %s' %(song.artist))
log ('Title : %s' %(song.title))
song.title = re.sub(r'\([^\)]*\)$', '', song.title)
return song
Although this works, the script fails later with the aforementioned error at this routine
PHP Code:
def deAccent(str):
return unicodedata.normalize('NFKD', unicode(str, 'utf-8'))
Relevant error from my debug log is
Code:
ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.TypeError'>
Error Contents: decoding Unicode is not supported
Traceback (most recent call last):
File "/home/xbmc/.xbmc/addons/script.cu.lrclyrics/default.py", line 40, in <module>
culrc_run('service')
File "/home/xbmc/.xbmc/addons/script.cu.lrclyrics/default.py", line 27, in culrc_run
gui.MAIN(mode=mode)
File "/home/xbmc/.xbmc/addons/script.cu.lrclyrics/resources/lib/gui.py", line 25, in __init__
self.main_loop()
File "/home/xbmc/.xbmc/addons/script.cu.lrclyrics/resources/lib/gui.py", line 52, in main_loop
self.myPlayerChanged()
File "/home/xbmc/.xbmc/addons/script.cu.lrclyrics/resources/lib/gui.py", line 210, in myPlayerChanged
if ( song and ( self.current_lyrics.song != song ) ):
File "/home/xbmc/.xbmc/addons/script.cu.lrclyrics/resources/lib/utilities.py", line 99, in __cmp__
return cmp(deAccent(self.artist), deAccent(song.artist))
File "/home/xbmc/.xbmc/addons/script.cu.lrclyrics/resources/lib/utilities.py", line 34, in deAccent
return unicodedata.normalize('NFKD', unicode(str, 'utf-8'))
TypeError: decoding Unicode is not supported
-->End of Python script error report<--
Some help with this would be really appreciated.
Thanks.