Kodi Community Forum
Help to set "UserRating" in a song using script - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Help to set "UserRating" in a song using script (/showthread.php?tid=371574)

Pages: 1 2 3 4 5


RE: Help to set "UserRating" in a song using script - sagrath - 2023-01-30

(2023-01-30, 01:16)jbinkley60 Wrote: One question is for your notification calls why isn't there a time value included ?  It isn't required but I am curious.

The notification on line 85 will not stay there, it's only for now while I'm creating the addon, to me "see" the addon working. Once it's done, will be removed, maybe as an option on settings to on/off the notification (still need to learn how to do this). I will only keep the notification on line 35, which is a notification when the music stops, as I see no reason to show notifications while the player is running. With the player running the ratings will be saved but without notification.

But is worth mention: even with the notification disabled, the refresh effect still happens. Only deactivating the "xbmc.executeJSONRPC" on line 91 the "refresh"effect is gone (but without this, the song will not be rating LOL)
 
(2023-01-30, 01:16)jbinkley60 Wrote: xbmc.executebuiltin("Notification(%s, %s, time=500)" % ("New 0 Rating", new_rating))

But I like the idea of put a timer in notifications. Sometimes I think they are too long to only show one simple line.  I will use in the future for sure.

if someone want's to try the addon, here is it: Song Auto Rating


RE: Help to set "UserRating" in a song using script - jbinkley60 - 2023-01-31

(2023-01-30, 01:57)sagrath Wrote: But I like the idea of put a timer in notifications. Sometimes I think they are too long to only show one simple line.  I will use in the future for sure.

if someone want's to try the addon, here is it: Song Auto Rating

I downloaded your addon and will play with it later today or tomorrow.  How do I reproduce the issue and what should I look for (just look for the screen refresh indication) ? 

I do see one minor thing with the lines:

            time.sleep(1) # wait for 60 seconds before checking again            

        if monitor.waitForAbort(1): # Sleep/wait for abort for 1 second: # Sleep/wait for abort for 1 second

I'll try to reproduce / fix the issue you are having and provide an improvement for if monitor.waitForAbort(1): # Sleep/wait for abort for 1 second


Thanks,

Jeff


RE: Help to set "UserRating" in a song using script - sagrath - 2023-01-31

(2023-01-31, 16:29)jbinkley60 Wrote: I downloaded your addon and will play with it later today or tomorrow.  How do I reproduce the issue and what should I look for (just look for the screen refresh indication) ? 

On line 91 there's a comented code:
# xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))

I forgot to uncoment befor packing and upload here.
just uncoment and the issue will hapen
to hide the notification when music is playing, just coment the notification on line 86

thanks forr your time
(2023-01-31, 16:29)jbinkley60 Wrote: if monitor.waitForAbort(1): # Sleep/wait for abort for 1 second: # Sleep/wait for abort for 1 second

oh yeah, just a typo, first I set to 60 seconds, and then change the time, but don't change the coment.


RE: Help to set "UserRating" in a song using script - jbinkley60 - 2023-02-01

(2023-01-31, 20:22)sagrath Wrote: On line 91 there's a comented code:
# xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))

I forgot to uncoment befor packing and upload here.
just uncoment and the issue will hapen
to hide the notification when music is playing, just coment the notification on line 86

Ok, I see the main problem.  You are basically using JSONRPC calls to pass a variable (i.e. get, increment and set) every second.  This is a heavy handed approach and is updating the Kodi database every second.  There may be a skin option to get rid of the pulsing but a better approach is to leverage your class to manage passing the variable / incrementing current_time.  Then use Playback started to get the current time value and playback stopped to set it.  While playing you would have something like self.current_time = 0 in your class init statement and increment it / check it as the song plays.   If you wanted to periodically check the playtime while the file is playing you can do what I do with bookmarks and check every so often (I save bookmarks every 30 seconds). 

For example:

if current_time % 30 == 0:
    set value in Kodi database via JSON RPC

I don't have time right now to modify your code but hopefully this helps.  Also, you need to check that your JSON get call actually returns an ID.  I tried playing a URL and it threw an error due to no ID since a URL wouldn't be in the Kodi database.


Thanks,

Jeff


RE: Help to set "UserRating" in a song using script - jbinkley60 - 2023-02-01

(2023-01-31, 20:22)sagrath Wrote: On line 91 there's a comented code:
# xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))

I forgot to uncoment befor packing and upload here.
just uncoment and the issue will hapen
to hide the notification when music is playing, just coment the notification on line 86


One other logic question for you with regards to getting the current_time via the JSON RPC call on a regular basis.  Are you wanting to update the rating based upon how long the user actually listens to the song or the position in the song ?  I ask because with your regular get approach your ratings will change more quickly if the user fast forwards or rewinds the song.  That could produce some interesting and unwanted results.  If you base it on the while waitforabort loop timer then you have the actual time the user listens to the song, regardless if the decide to rewind or fast forward.

On the addon I shared, I am setting  / saving the bookmark on a periodic basis so I want to know the exact position of current play.  I think you may just be wanting the total time played vs. current play position.  If so, the loop timer approach would be much simpler. 


Thanks,

Jeff


RE: Help to set "UserRating" in a song using script - black_eagle - 2023-02-01

(2023-02-01, 15:07)jbinkley60 Wrote: This is a heavy handed approach and is updating the Kodi database every second.  There may be a skin option to get rid of the pulsing but a better approach is to leverage your class to manage passing the variable / incrementing current_time. 

I disagree!!  The correct way for a python addon to manipulate the databases in Kodi is via xbmc.executeJSONRPC().  I don't think that doing that should affect the GUI in any way.

EG, when scanning music tags, Kodi will skip the "Encoded by" tag (TENC for id3v2, 'ENCODEDBY' for ape/ogg).  If I want to write some python to add TENC to the end of say, the comment tag of a song, I would not expect the GUI to flicker whilst doing so, regardless of the speed of the scanning and the calls to/from the database.  After all, it doesn't when core is scanning and or/updating the database, so why should it if python is scanning and updating the database?

If indeed it does, then I would suggest that it's a bug.


RE: Help to set "UserRating" in a song using script - jbinkley60 - 2023-02-01

(2023-02-01, 16:34)black_eagle Wrote: I disagree!!  The correct way for a python addon to manipulate the databases in Kodi is via xbmc.executeJSONRPC().  I don't think that doing that should affect the GUI in any way.

EG, when scanning music tags, Kodi will skip the "Encoded by" tag (TENC for id3v2, 'ENCODEDBY' for ape/ogg).  If I want to write some python to add TENC to the end of say, the comment tag of a song, I would not expect the GUI to flicker whilst doing so, regardless of the speed of the scanning and the calls to/from the database.  After all, it doesn't when core is scanning and or/updating the database, so why should it if python is scanning and updating the database?

If indeed it does, then I would suggest that it's a bug.

I am not saying that JSON RPC is the wrong way to update the database.  I am just questioning whether continually getting/setting/getting the userrating value via JSON RPC every second is the best approach.   It would be less overhead of grabbing and setting less frequently based upon something other than every second, especially if the main goal is simply to pass a variable within the addon..  I agree it is likely a bug causing the flickering and shouldn't this.  However if you couple this with my second post about whether he is looking for the current position vs. the total time played, a review of the logic approach is what I am suggesting.


Thanks,

Jeff


RE: Help to set "UserRating" in a song using script - jbinkley60 - 2023-02-01

(2023-01-31, 20:22)sagrath Wrote:
(2023-01-31, 16:29)jbinkley60 Wrote: I downloaded your addon and will play with it later today or tomorrow.  How do I reproduce the issue and what should I look for (just look for the screen refresh indication) ? 

On line 91 there's a comented code:
# xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))

I forgot to uncoment befor packing and upload here.
just uncoment and the issue will hapen
to hide the notification when music is playing, just coment the notification on line 86

thanks forr your time
(2023-01-31, 16:29)jbinkley60 Wrote: if monitor.waitForAbort(1): # Sleep/wait for abort for 1 second: # Sleep/wait for abort for 1 second

oh yeah, just a typo, first I set to 60 seconds, and then change the time, but don't change the coment.

Ok.  Here's a simple fix.  I added a new variable called original_rating = 0.  This it is then checked against your new calculated_rating variable in the timer loop.  Only when calculated_rating is greater than the original_rating will it set the Kodi database with a new value.  Thus you aren't writing the same value over and over to the database.  I also modified the waitforabort loop and added time values to the notification messages.  I tested this and see the music database userrating only being updated when a new userrating value is calculated.

python:

original_rating = 0

while not monitor.abortRequested():    
    try:
        while True:

            if xbmc.Player().isPlayingAudio():        
                # Retrieve the currently playing song
                xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"JSONRPC.Introspect","id":1}')
                result = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":0,"properties":["userrating"]},"id":1}')
                
                # Extract the song ID and rating
                song_details = json.loads(result)["result"]["item"]
                song_id = song_details["id"]
                song_rating = song_details["userrating"]
                
                # To have all the necessary time calculations.
                song = player.getMusicInfoTag()
                song_title = song.getTitle()
                song_length = song.getDuration()        
                song_parts = int(song_length / 11)
                current_time = int(player.getTime())
                
                # To avoid an error where the calculation would be divided by zero
                if current_time == 0:
                    xbmc.sleep(1000)

                calculated_rating = int(current_time / song_parts)
                
                monitor.onPlayBackStarted()
                
                # For a future try to idenfy the song change without stopping the player,
                # when the song ends and the next one in the playlist starts.
                # if self.current_song == "":
                    # self.current_song = xbmc.getInfoLabel('MusicPlayer.Title')
                
                # If the song has no rating yet, or the rating is "0", this will be its new rating.
                if song_rating == 0:
                    new_rating = int(current_time/song_parts)
                
                # If the song already has a rating, here the current rating value will
                # be added to the new rating calculation, to obtain an average rating.
                elif song_rating != 0:
                    new_rating = int((song_rating + calculated_rating) / 2)
                
                # Notification only to "see"the script working.
                if calculated_rating > original_rating:
                    xbmc.executebuiltin("Notification(%s, %s, time=2000)" % ("New 0 Rating", new_rating))       
                
                # Saving the new rating as the song progresses.
                # ----------------------------------------------------------------------------
                # HERE IS WHERE IT CAUSES THE "REFRESH" EFFECT, I NEED TO FIND A WAY AROUND IT.
                # ----------------------------------------------------------------------------
                #xbmc.log('Autorater is here: ' + str(current_time), xbmc.LOGINFO)
                    xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))
                    original_rating = calculated_rating
            else:
                monitor.onPlayBackStopped()
                original_rating = 0
            
            monitor.status_check()
            #time.sleep(1) # wait for 60 seconds before checking again
            
            if monitor.waitForAbort(1): # Sleep/wait for abort for 1 second
                break                   # Abort was requested while waiting. Exit the while loop.
    
    except Exception as e:
        xbmc.executebuiltin("Notification(%s, %s)" % ("An error occurred: ", e))




Thanks,

Jeff


RE: Help to set "UserRating" in a song using script - sagrath - 2023-02-02

(2023-02-01, 17:11)jbinkley60 Wrote: Ok.  Here's a simple fix.  I added a new variable called original_rating = 0.  This it is then checked against your new calculated_rating variable in the timer loop.  Only when calculated_rating is greater than the original_rating will it set the Kodi database with a new value.

WOW!!! A simple elegant solution!! it's now running om my main Kodi, and the refresh effect happens very rarely. But I think there is no way to avoid this, because when updating the database, kodi "needs to update" right?
(2023-02-01, 17:11)jbinkley60 Wrote: I also modified the waitforabort loop and added time values to the notification messages.  I tested this and see the music database uerrating only being updated when a new uerrating value is calculated.

Yeas, 
this was the first thing I "imagined" when I thought about the general idea of ​​​​the addon, but the inexperience in addon for Kodi spoke louder. Anyway: THANK YOU VERY MUCH for your help and your time @jbinkley60!!!!! 
I'll try a few more ideas and try to make them available in the repository for everyone


RE: Help to set "UserRating" in a song using script - jbinkley60 - 2023-02-02

(2023-02-02, 00:53)sagrath Wrote: Yeas, 
this was the first thing I "imagined" when I thought about the general idea of ​​​​the addon, but the inexperience in addon for Kodi spoke louder. Anyway: THANK YOU VERY MUCH for your help and your time @[b]jbinkley60!!!!! [/b]
I'll try a few more ideas and try to make them available in the repository for everyone

Here's another fix which addresses detecting whether a playing file is in the Kodi database or not, removing the error which was occurring.  I also made a logic change  on the current_time detection to eliminate the sleep 1 second.  You might want to move this to GitHub to make it easier to collaborate.  Also, I am not sure your onPlayBackStopped method is working the way you want due the scope of some variables.  Additional testing will be needed to confirm.

python:


original_rating = calculated_rating = 0

while not monitor.abortRequested():    
    try:
        while True:

            if xbmc.Player().isPlayingAudio():        
                # Retrieve the currently playing song
                xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"JSONRPC.Introspect","id":1}')
                result = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":0,"properties":["userrating"]},"id":1}')
                
                # Extract the song ID and rating
                song_details = json.loads(result)["result"]["item"]
                if "id" in song_details:               # Ensure music file exists in Kodi database
                    song_id = song_details["id"]   
                    song_rating = song_details["userrating"]
                
                    # To have all the necessary time calculations.
                    song = player.getMusicInfoTag()
                    song_title = song.getTitle()
                    song_length = song.getDuration()        
                    song_parts = int(song_length / 11)
                    current_time = int(player.getTime())
                
                    # To avoid an error where the calculation would be divided by zero
                    #if current_time == 0:
                    #xbmc.sleep(1000)

                    if current_time > 0:
                        calculated_rating = int(current_time / song_parts)
                
                    monitor.onPlayBackStarted()
                
                    # For a future try to idenfy the song change without stopping the player,
                    # when the song ends and the next one in the playlist starts.
                    # if self.current_song == "":
                        # self.current_song = xbmc.getInfoLabel('MusicPlayer.Title')
                
                    # If the song has no rating yet, or the rating is "0", this will be its new rating.
                    if song_rating == 0:
                        new_rating = int(current_time/song_parts)
                
                    # If the song already has a rating, here the current rating value will
                    # be added to the new rating calculation, to obtain an average rating.
                    elif song_rating != 0:
                        new_rating = int((song_rating + calculated_rating) / 2)
                
                    # Notification only to "see"the script working.
                    if calculated_rating > original_rating:
                        xbmc.executebuiltin("Notification(%s, %s, time=2000)" % ("New 0 Rating", new_rating))       
                
                    # Saving the new rating as the song progresses.
                    # ----------------------------------------------------------------------------
                    # HERE IS WHERE IT CAUSES THE "REFRESH" EFFECT, I NEED TO FIND A WAY AROUND IT.
                    # ----------------------------------------------------------------------------
                    #xbmc.log('Autorater is here: ' + str(current_time), xbmc.LOGINFO)
                        xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))
                        original_rating = calculated_rating
                else:
                    monitor.onPlayBackStopped()
                    original_rating = calculated_rating = 0
            
            monitor.status_check()
            #time.sleep(1) # wait for 60 seconds before checking again
            
            if monitor.waitForAbort(1): # Sleep/wait for abort for 1 second
                break                   # Abort was requested while waiting. Exit the while loop.
    
    except Exception as e:
        xbmc.executebuiltin("Notification(%s, %s)" % ("An error occurred: ", e))




Thanks,

Jeff


RE: Help to set "UserRating" in a song using script - sagrath - 2023-02-03

(2023-02-02, 15:39)jbinkley60 Wrote: You might want to move this to GitHub to make it easier to collaborate. 

yeah, I have a personal github with some projects, I will move to there. I've learned how to make a repo too!
(2023-02-02, 15:39)jbinkley60 Wrote: Also, I am not sure your onPlayBackStopped method is working the way you want due the scope of some variables.

yeah, I'm think it´s not workin anymore. But I'll check this too!


RE: Help to set "UserRating" in a song using script - jbinkley60 - 2023-02-03

(2023-02-03, 15:00)sagrath Wrote: yeah, I have a personal github with some projects, I will move to there. I've learned how to make a repo too!


I have a separate repo for my main addon.  It makes it easy to push out updates to users.  I use the official Kodi repo as much as possible for my addons.


Jeff


RE: Help to set "UserRating" in a song using script - sagrath - 2023-02-04

Here, I ulpload to my private github!

Song Auto rating Girthub  

Continuing my saga, here are some thoughts:

When I came up with this script, I thought of certain details:
Well, for the script to work 100% and have accurate evaluations, the situation must occur as follows:

When starting the song, the evaluation calculations start and two variants are taken into account:
Variant A: If the music has original empty note or equal to Zero, the script will divide the music in 11 parts and calculate the note being the part 1/11 = rating 0, 2/11 = rating 1, 3/11 = rating 2.... 10/11 = rating 9 and 11/11 = rating 10.

Variant B: If the song already has some rating, the script will calculate the same as variant A, and will calculate the initial rating, plus the calculated rating and divide by 2, thus making an average note.

And I thought of the following five scenarios in which music is evaluated:

Scenario A: The music plays to the end and the player stops.
Occurs when the song is the only or last song in the playlist, and the repeat function is disabled.

Scenario B: Music is stopped by user action:
Occurs when the user presses the STOP button, and the player stops, regardless of which position the music is in.

Scenario C: The song plays until the end and the next song starts:
Occurs when the song is not the only or last song in the playlist, or when the repeat function is activated.

Scenario D: The song is skipped by the user, either to the next one in the playlist, or the previous one:
Occurs when the user presses the skip-forward or skip-backwards buttons, causing the current song to be stopped, but without the player stopping.

Scenario E: The music ends and then starts:
It happens when the song is the only one in the playlist and the repeat function is activated.

While writing the code, I noticed that scenario A was easily solved with:

else:
      monitor.onPlayBackStopped()

which calls the function "def onPlayBackStopped(self):" and it's good.

The scenario B uses the same funcion as scenario A, so it's good too!

scenario C is possible as long as the evaluation of the music occurs in real time, because in this way, regardless of the user's action, the music will receive the note along which it is played, but it will not take into account empty notes or zero notes , because as soon as it receives a score of 1 (that is, the second 1/11 of the song) the calculation will change to a song with a score != of zero or empty.

That is, either it is possible to evaluate in real time with automatic evaluation of the next song in the playlist, or it is possible to evaluate the music according to its current score, which would be current score plus calculated score divided by 2.

complicated right?

Scenario E is the same as scenario C, the difference is that the song will be re-evaluated at each execution.

As for scenario D, I really couldn't run it at all. By the way, I even managed it, because if I use scenario C, when skipping the song, there will be an evaluation of the next or previous one.

Does anyone have any ideas on how to check when the user skips the song?
I did some tests over the week, and managed to find a logic where I got scenarios A and B and C taking into account zero and non-zero grades. In other words, only scenario D was missing.

I'm going crazy already looking for a solution. Who told me to get into programming hahahahaha!

by the way here's the code: (not in github, because there I keep the last of @jbinkley60 show me.

python:

import xbmc
import xbmcaddon
import json
import time

class Monitor(xbmc.Monitor):
    def __init__(self):
        self.is_library_song = False
        pass

    def status_check(self):
        # perform monitor status check
        pass

    def onPlayBackStarted(self):
        self.is_library_song = True

    # When the song ends, either by user action, or when the song is
    # the last in the playlist and the "repeat" function is disabled.
    def onPlayBackStopped(self):
        if self.is_library_song and current_time > 5:
            # If the song has no rating yet, or the rating is "0", this will be its new rating.
            if song_rating == 0:
                new_rating = int(current_time/song_parts)

            # If the song already has a rating, here the current rating value will
            # be added to the new rating calculation, to obtain an average rating.
            elif song_rating != 0:
                new_rating = (song_rating + calculated_rating) / 2

            # Saving the new rating as the song stops.
            xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))
            xbmc.executebuiltin("Notification(%s, %s)" % ("New Rating", new_rating))
            self.is_library_song = False

def calculate_zero_rating(calculated_rating):
    # 2 seconds before music ends, the calculation
    # will be the the value in "calculated_rating"
    if (current_time - 2) >= song_length:
        new_rating = int(current_time/song_parts)
        xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))
        xbmc.executebuiltin("Notification(%s, %s, time=2000)" % ("New 0 Rating", new_rating))
    else:
        xbmc.executebuiltin("Notification(%s, %s, time=2000)" % ('{} Waiting:'.format(song_title), 'Seconds: {}'.format(current_time - 2)))
        
def calculate_positive_rating(calculated_rating):
    # 2 seconds before music ends, the calculation 
    # will be the current song rating, plus the calculated_rating
    # divided by 2, to get an average ratings
    if (current_time - 2) >= song_length:
        new_rating = int((song_rating + calculated_rating) / 2)
        xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.SetSongDetails","params":{"songid": %d, "userrating":%d},"id":1}' % (song_id, new_rating))
        xbmc.executebuiltin("Notification(%s, %s, time=2000)" % ("New Positive Rating", new_rating))
    else:
        xbmc.executebuiltin("Notification(%s, %s, time=2000)" % ('{} Waiting:'.format(song_title), 'Seconds: {}'.format(current_time - 2)))

monitor = Monitor()
player = xbmc.Player()
calculated_rating = 0

while not monitor.abortRequested():
    try:
        while True:
            if xbmc.Player().isPlayingAudio():
                # Retrieve the currently playing song
                xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"JSONRPC.Introspect","id":1}')
                result = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":0,"properties":["userrating"]},"id":1}')

                # Extract the song ID and rating
                song_details = json.loads(result)["result"]["item"]
                # Ensure music file exists in Kodi database
                if "id" in song_details:               
                    song_id = song_details["id"]
                    song_rating = song_details["userrating"]

                    # To have all the necessary time calculations.
                    song = player.getMusicInfoTag()
                    song_title = song.getTitle()
                    song_length = song.getDuration()
                    song_parts = int(song_length / 11)
                    current_time = int(player.getTime())

                    # To avoid an error where the calculation would be divided by zero
                    if current_time > 0:
                        # here is the calculation of the current playing ratings
                        calculated_rating = int(current_time / song_parts)
                    
                    # When music starts, "self.is_library_song" is set to True
                    monitor.onPlayBackStarted()
                    
                    # If song has rating empty or zero, the calculations
                    # will be made in "def calculate_zero_rating()" 
                    if song_rating == 0:
                        calculate_zero_rating(calculated_rating)
                    
                    # If song already has a non-zero rating, the calculations
                    # will be made in "def calculate_positive_rating()" 
                    if song_rating > 0:
                        calculate_positive_rating(calculated_rating)
                
            else:
                # when the song ends, with or 
                # without user intervention.
                monitor.onPlayBackStopped()

            monitor.status_check()
            
            # Sleep/wait for abort for 1 second
            if monitor.waitForAbort(1): 
                 # Abort was requested while waiting. Exit the while loop.
                break                  

    except Exception as e:
        xbmc.executebuiltin("Notification(%s, %s)" % ("An error occurred: ", e))

In this logic, I do not use the sugestion of @jbinkley60 to use new variable called original_rating = 0, because now the song only wil be rating 2 seconds before has stopped or ended.

But as i said above,  I can't get to scenario D, because I can't find a logic to increment within that scope. I also can't find in the Kodi documentation how to identify when the user triggers skip-forward/backward.

Does anyone have a suggestion or opinion?


RE: Help to set "UserRating" in a song using script - izprtxqkft - 2023-02-04

Quote:Does anyone have any ideas on how to check when the user skips the song?
let me try to answer with a question that you can check on
if the user skips wouldnt it still call back to monitor.onPlayBackStopped() because the current song has effectively stopped
if so, could you check if something else is playing after in that event then you have differentiated between a stop and a skip


RE: Help to set "UserRating" in a song using script - sagrath - 2023-02-04

Oh! hello @jepsizofye ! Thanks to your time!

I've just update my previous post with the "new logic that drives me crazy" and the "new code".

So about your question:

(2023-02-04, 02:38)jepsizofye Wrote: if so, could you check if something else is playing after in that event then you have differentiated between a stop and a skip

So that's what I'm trying to do: differentiate a stop from a jump. For the stop monitor.onPlayBackStopped() is what sends the logic to "def onPlayBackStopped(self)". But for the jump, the script needs to identify that "the current song was interrupted but the player wasn't", save the calculations on the skipped song, and then start new calculations for the new song that is playing.

Doing a check by the name of the song, I even managed to identify when the song "changes" but then the calculations all go to the song that is currently playing, and not to the one that was skipped.

Like I said, I'm going crazy already hahaha