$INFO[MusicPlayer.UserRating] doesn't change during playback?
#1
I've made a script to set a song's user-rating to a value that is predefined in skin settings. This acts as a sort of threshold for a Like/Unlike binary rating system that can be overlayed on top of the normal /10 ratings without removing existing user ratings. So if the threshold is set to 8, the script will set a song's user-rating to 8 when it is executed. And a widget will also use this threshold value as a filter, in effect working as a Liked songs smart playlist. 

This all works fine, and I 'unlike' a song by running the script to set the user rating to 0, effectively removing it altogether.

I wanted to incorporate the scripit into my player controls to give the option to 'like' the currently playing song, or 'unlike' the song if it is already liked.

Here I run into problems because the infolabel MusicPlayer.UserRating appears not to update dynamically during song playback. So you have to stop and start or go next and then previous before it will show the value that it was set to via the script. @DaveBlake do you know if this is expected behaviour?
Reply
#2
(2023-02-10, 02:26)realcopacetic Wrote: I've made a script to set a song's user-rating to a value that is predefined in skin settings. This acts as a sort of threshold for a Like/Unlike binary rating system that can be overlayed on top of the normal /10 ratings without removing existing user ratings. So if the threshold is set to 8, the script will set a song's user-rating to 8 when it is executed. And a widget will also use this threshold value as a filter, in effect working as a Liked songs smart playlist. 

This all works fine, and I 'unlike' a song by running the script to set the user rating to 0, effectively removing it altogether.

I wanted to incorporate the scripit into my player controls to give the option to 'like' the currently playing song, or 'unlike' the song if it is already liked.

Here I run into problems because the infolabel MusicPlayer.UserRating appears not to update dynamically during song playback. So you have to stop and start or go next and then previous before it will show the value that it was set to via the script. @DaveBlake do you know if this is expected behaviour?

You might want to look at this thread. @sagrath has developed some similar functionality and has dynamic updates working.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#3
Thanks @jbinkley60, will check it out!
Reply
#4
sorry @jbinkley60 @sagrath - I got a bit lost in the code as I'm fairly new to all this so I'm not sure if it's doing what I specifically am trying to do. As I understand it, you can update the music player infolabels with player.UpdateInfoTag(), but I just can't get it to work for some reason... This is the example:

python:

Update info labels for currently playing item.

Example:
updateInfoTag()
void XBMCAddon::xbmc:Tonguelayer::updateInfoTag()
...
item = xbmcgui.ListItem()
item.setPath(xbmc.Player().getPlayingFile())
item.setInfo('music', {'title' : 'foo', 'artist' : 'bar'})
xbmc.Player().updateInfoTag(item)
...

I tried to incorporate it into my code, but using the new MusicInfoTag method instead of setInfo.

So in the below function, a listitem dbid and an interger for the rating (rating_threshold) are passed as parameters and a json call updates the song details. This is fine and the ListItem.UserRating updates as expected.

So then my code is trying to establish if the dbid of the item just updated is the same as the dbid of the item currently playing. If it is I create a listitem and assign it the new user rating value via MusicInfoTag. Up to now it's still working ok I think. I also assign it the path of the item being played. I'm not sure if this is required, but I noticed they did it in the documentation example so I did too.

But then according to the example in the documentation, I should be able to pass the new ListItem to xbmc.Player().updateInfoTag() to update the player info labels. Except when I try this nothing happens and I'm not really sure how to see what's going wrong as there is no error, just nothing happens to MusicPlayer.UserRating.

python:

def rate_song(**kwargs):
    dbid = int(kwargs.get('id', False))
    rating_threshold = int(kwargs.get('rating', 7))
       
    json_call('AudioLibrary.SetSongDetails', params={'songid': dbid, 'userrating': rating_threshold})
           
    player = xbmc.Player()
    player_dbid = int(xbmc.getInfoLabel('MusicPlayer.DBID')) if player.isPlayingAudio() else None
    if dbid == player_dbid:
        player_path = player.getPlayingFile()
        item = xbmcgui.ListItem(path=player_path)
        musicInfoTag = item.getMusicInfoTag()
        musicInfoTag.setUserRating(rating_threshold)
        player.updateInfoTag(item)

I have a service running in the addon so my backup plan is to set a window property to take MusicPlayer.UserRating onAVChange() and then overwrite it in my rate_song() script. But it seemed like it would be much cleaner to just be able to update the MusicPlayer.UserRating label at the point which the script is run given that doing so should be possible.

Do you have any ideas what's missing from this?
Reply
#5
Hello!!! @realcopacetic, sorry for the late reply.
So, I've noted this behavior, the userrating doesn't change during playback. The value is saved on database, but it's only show after the playback of that song ended or stopped. 

In my script I had a problem similiar, when the userrating was saved on database during playback, messed up with the calculations, but not update in the song informations.
Reply
#6
(2023-02-14, 15:10)sagrath Wrote: Hello!!! @realcopacetic, sorry for the late reply.
So, I've noted this behavior, the userrating doesn't change during playback. The value is saved on database, but it's only show after the playback of that song ended or stopped. 

In my script I had a problem similiar, when the userrating was saved on database during playback, messed up with the calculations, but not update in the song informations.

Thanks for the reply @sagrath - In the end I resorted to setting a window property that picks up MusicPlayer user rating when playback starts and then will be over-written by my rating function when it is run. Then it's cleared when playback stops.
Not perfect, but it works more or less so that I can show a 'liked' indicator for the currently playing song when someone rates it during playback.
Reply
#7
@sagrath @realcopacetic This is because the song information is only fetched from the db once.  It might be possible to re-fetch ratings if they are updated (that happens asynchronously) but I'd have to look at that.
Learning Linux the hard way !!
Reply
#8
thanks for the explanation @black_eagle so does that mean that xbmc.Player().updateInfoTag(item) would update the item that is currently playing, but that you wouldn't see the change, until you stopped playback and played that item again?
Reply
#9
(2023-02-14, 22:41)realcopacetic Wrote: does that mean that xbmc.Player().updateInfoTag(item) would update the item that is currently playing, but that you wouldn't see the change, until you stopped playback and played that item again?

I don't know without testing it and looking to see what happens.  Do you perhaps have some code and skin I can test with?  Changing the userrating in Confluence appears to update immediately if done by pressing <i> and then changing the rating.
Learning Linux the hard way !!
Reply
#10
@black_eagle - yes that also updates it for me if I go through <i> and then adjust the rating in there. I'm trying to update it with a script that can be triggered either through the contextmenu of the song listitem or in my musicplayer widget.

My skin is set up and ready to test with if that's ok to use - you can install it from the repo here: https://realcopacetic.github.io and it will automatically install the corresponding script.

To get the experiment set up, you just need to

1. Go to settings > Copacetic > Look and Feel and set a number for Liked Music Threshold. Then it will use this value to set the user rating. 
2. Set the <visibility>true</visibility> to true in the window Custom_1199_Test_Label.xml, it will display the MusicPlayer.UserRating in the top left of the screen.

My test is as follows.

1 Navigate to a song in your library and start playback.
2 Then press c for context menu and choose 'Like song'.
3 You should see a heart appear next to the list item, meaning it's user rating has been set to the value you set for Liked Music Threshold in settings.
4 The MusicPlayer.UserRating infolabel will not update.
5 If you stop playback of the song and then start it again, the MusicPlayer.UserRating will now update.
6 If you press <i> on the playing song and then press right once to get to 'Set my Rating', you can manipulate the rating with either up/down or by pressing enter to bring up DialogSelect.xml. 
7 As soon as you exit the infoscreen to return focus to the music window, the user rating label will update to reflect the latest change.
8 If you change the user rating of the playing song via contextmenu and then press <i> then <i> again to exit, the infolabel does NOT update.

So indeed it looks as if it is only fetched once on playback starting and then once on exiting <i> if it is updated specifically using the set rating function on the infoscreen.

Apologies if this is not what you meant by supplying code/test and if you need something more standardised for Confluence
Reply
#11
@realcopacetic Thanks, that is exactly what I was after.  Sadly, the contents of Custom_1199_Test_label.xml are as follows.

xml:
<?xml version="1.0" encoding="UTF-8"?>
<window type="dialog" id="1199">
    <visible></visible>
    <animation effect="fade" start="100" end="0" delay="1080" time="360">WindowClose</animation>
    <zorder>3</zorder>
    <controls>
        <control type="label">
            <align>right</align>
            <label>hello...$INFO[Window(home).Property(MusicPlayer_AlbumArtist)]</label>
        </control>
    </controls>
</window>

I guess that that is wrong, and I changed the code to $INFO[MusicPlayer.UserRating] but I still don't see a rating on the screen (or indeed hello!!).  Skinning is not my strong point at all, so if you could advise me what to do, I'd be grateful.

Thanks.
Learning Linux the hard way !!
Reply
#12
Oh yeah that looks old @black_eagle . Can you just check what version of the skin you are. It should be 0.9.87. I checked in the repo and it looks ok. Could you try to update? Maybe I updated it after you installed? I've done a few updates today.

Thanks for looking into this!
Reply
#13
@realcopacetic It's 0.9.85 that's installed and it's not currently showing any updates available.  However, I have got it working now and can reproduce your issue so I'll have a dig around and see what I can figure out.
Learning Linux the hard way !!
Reply
#14
Thanks @black_eagle something else for me to figure out hehe. I'll try updating on my other device later to see if I'm having the same issue on the update. It's strange cos everything looks ok from Github: https://raw.githubusercontent.com/realco...addons.xml

Anyway, sorry for taking your time on that unrelated issue!
Reply
#15
It appears that although the db (and associated musicinfotag for the item) are correctly updated, the NotifyItemUpdated call for music items doesn't trigger the GUI to reload changed listitems.  So, I can see in the debugger that the userrating has changed in both the database and the infotag but the gui does not display that changed info.

I have some code that does update it correctly however.  Or at least, I think it's correct in that it works, art stays the same etc.

@realcopacetic I can get you a test build later if you would like to make sure it does actually do what you want if you let me know what platform(s) you need.  If it's Linux, you'll need to build it from my branch when I push it, but I can give you details for that if necessary.
Learning Linux the hard way !!
Reply

Logout Mark Read Team Forum Stats Members Help
$INFO[MusicPlayer.UserRating] doesn't change during playback?0