Kodi Community Forum

Full Version: CU LRC with radio streams
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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

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.pyHuh

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.
Hi black_eagle
i use tunein addon radio in xbmc
works great with cu lrc but, like you said you need to enter
the music visualisation screen each time the song changes.
i'm not a programer but i would love to see it fixed

any lock with this issue?

Refael
Oh how I love when some old threads help me out to go in the right direction Smile

My problem was when using radio streams through the IPTV Simple Client - whenever i executed the script to get the lyrics, it would search for the PVR channel number (something like PVR.xyxyxy).

So, I had to replace:
Code:
if not song.artist and xbmc.getCondVisibility('Player.IsInternetStream'):
with:
Code:
if not song.artist and xbmc.getCondVisibility('Pvr.IsPlayingRadio'):
in utilities.py

I copied the whole section so now it works for both internet streams (playing through PVR or playing through some other radio plugin).
I guess kodi doesn't recognize internet radio streams that play through PVR plugins as regular internet streams.
thanx for the tip!
i'll add your code to the cu lrc lyrics addon.