2014-09-01, 00:14
Firstly, I'd like to say what a great addon this is !!
However, I've never been able to grab lyrics from a live radio stream (and I listen to the radio a lot). I added a bunch of logging to see if I could determine why it wouldn't work for me and it turns out that the addon was trying to find lyrics for the name of the radio station I was listening to, and not a song. No wonder it never found anything !!!
I played around a bit with the current song routine in an effort to correct this. I found that using the infolabel to determine a duration of zero (live stream) was hit and miss, probably due to a slight amount of buffering. I changed this to a json call, which appears to always return a value of zero for a live stream. I also found that the current code expects the artist field to be empty, but in testing with various live streams in the UK, this is not the case and the artist field is invariably populated with a string pertaining to the radio station. E.G 'planetrock.aac -' or 'Viking FM -'. I therefore changed the criteria from empty artist field to empty title field.
Getting the artist and title is done with another json call after which the script already has code to parse the result and split it into the correct fields.
The relevant code that I have changed in utilities.py is as follows
This does work (for me at any rate), but only if you enter the music visualisation screen each time the song changes. I have an idea about updating when the song changes. Need a variable that holds the last song title which is then checked against the current title.
I'm really not sure though where this should go. In myPlayerChanged in gui.py
I'm aware that Ronie wrote it mainly to look through playlists and that triggering it may be difficult with a live stream. I'd love to be able to get it to work though. It really would be icing on my cake.
However, I've never been able to grab lyrics from a live radio stream (and I listen to the radio a lot). I added a bunch of logging to see if I could determine why it wouldn't work for me and it turns out that the addon was trying to find lyrics for the name of the radio station I was listening to, and not a song. No wonder it never found anything !!!
I played around a bit with the current song routine in an effort to correct this. I found that using the infolabel to determine a duration of zero (live stream) was hit and miss, probably due to a slight amount of buffering. I changed this to a json call, which appears to always return a value of zero for a live stream. I also found that the current code expects the artist field to be empty, but in testing with various live streams in the UK, this is not the case and the artist field is invariably populated with a string pertaining to the radio station. E.G 'planetrock.aac -' or 'Viking FM -'. I therefore changed the criteria from empty artist field to empty title field.
Getting the artist and title is done with another json call after which the script already has code to parse the result and split it into the correct fields.
The relevant code that I have changed in utilities.py is as follows
PHP Code:
def current():
song = Song.by_offset(0)
log('At this point, song is : %s' %(song))
my_json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": [ "duration"], "playerid": '"0"' }, "id": "AudioGetItem"}')
my_json_response=simplejson.loads(my_json_query)
our_time_remaining = my_json_response['result']['item']['duration']
log('Time Remaining for player is %s' %(our_time_remaining))
if not our_time_remaining and song.title == "":
# no artist and infinite playing time ? We probably listen to a radio
# which usually set the song title as "Artist - Title" (via ICY StreamTitle)
log('Looking at a radio stream !!')
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']
log('Got a title : %s' % (song.title))
song.title = song.title.encode('utf-8')
sep = song.title.find("-")
if sep > 1:
song.artist = song.title[:sep - 1].strip()
song.title = song.title[sep + 1:].strip()
# The title in the radio often contains some additional
# bracketed information at the end:
# Radio version, short version, year of the song...
# It often disturbs the lyrics search so we remove it
song.title = re.sub(r'\([^\)]*\)$', '', song.title)
return song
This does work (for me at any rate), but only if you enter the music visualisation screen each time the song changes. I have an idea about updating when the song changes. Need a variable that holds the last song title which is then checked against the current title.
PHP Code:
if song.title !=lastsongtitle:
lastsongtitle=song.title
do_search_for_lyrics
I'm really not sure though where this should go. In myPlayerChanged in gui.py
I'm aware that Ronie wrote it mainly to look through playlists and that triggering it may be difficult with a live stream. I'd love to be able to get it to work though. It really would be icing on my cake.