Help to set "UserRating" in a song using script
#61
(2023-02-06, 22:26)sagrath Wrote: YES!!!!!!!!!!!!!!!! yesyesyesyes!!!!!!!!!!!

THATS IT!!!!!!!!!!!!!!! @jbinkley60  you are a GENIOUS!!!!!!!!!!!!

It is working EXACTLY as I envisioned. The music starts, the calculations are executed and are only applied when the music changes or stops (either by user intervention or "naturally" when reaching the end).
And your last suggestion made me see where I was going wrong:
In the other codes, the song data was constantly being consulted, so the values ​​were saved in the wrong song. With your suggestion I realized that the data should be consulted only once, and only be consulted again if the music changes. (actually I had thought about it before, but at some point I forgot lol).

Anyway: Here is the final code. now I'm going to apply the tweaks to hide the notifications and also to disable the addon (for those who don't want to "rank" their songs at some point).

Glad it's working for you.  I noticed that you didn't use the current_id variable and reused song_id on lines 83 and 90.  Your way will work as long as you maintain the order of operation (i.e. update the original song_id) and then get a new value for song_id from the new song).  I kept the variables separate to avoid maintaining this level of strictness in code.  Overloading variables like this is fine as long as you maintain the proper execution sequence.  I also noticed that you dropped the code which checks to ensure the music playing is in the Kodi music database.  I'd suggest adding that back in.
Quote:PS. This is not over yet, after including the settings, I'm planning to include a "album rating" in this code. Where the Album Rating will be calculated by averaging the notes of the songs. What you think?

This actually should be pretty easy.  Get the ratings from all of the tracks in an album, average the ratings and assign the result to the album.  One question, is there a range on your userratings (i.e. 0 to some value) or will longer songs naturally have a higher potential rating due to a longer play time ? 


Thanks,

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
#62
(2023-02-06, 23:13)jbinkley60 Wrote: One question, is there a range on your userratings (i.e. 0 to some value) or will longer songs naturally have a higher potential rating due to a longer play time ? 

The tempo of the music doesn't really matter. The song's tempo will always be divided into 11 equal parts, and then the note will be applied as soon as you play those parts.

A 3 minute song has 180 seconds which divided into 11 would be about 16.5 seconds. If it plays only 1 minute and 16 seconds and the music is skipped/stopped, the music will have played only 76 seconds or only 4 parts (16.5 * 4 = 66 and 16.5 * 5 = 85.2) that is, the music has not yet entered the 5 part, it was stopped at part 4 and will receive a 3 because:
1st part = 0 rating,
2nd part = 1 rating,
3rd part = 2 rating,
4th part = 3 rating.

the same goes for Iced Earth's Dante's Inferno, the song is 16:29 (989 seconds). if you play until 11:28 the song will have played only 7 parts, and will receive a score of 6. I tried to think of other ways, but I couldn't. What do you think?
 
(2023-02-06, 23:13)jbinkley60 Wrote: I also noticed that you dropped the code which checks to ensure the music playing is in the Kodi music database.  I'd suggest adding that back in.

Oh yes I will add back, the code I post it's not the Release code, only the final working code, now the logic is finished, I will now working to avoid possible errors, maybe not consider songs below "x" seconds, like the intro to the Offspring album Smash, which is only 26 seconds long... it would be silly (I think) to calculate a "song" like that. 
But if the album rating idea I mentioned before "works out", then even short songs should be calculated.
 
(2023-02-06, 23:13)jbinkley60 Wrote: I noticed that you didn't use the current_id variable and reused song_id on lines 83 and 90.  Your way will work as long as you maintain the order of operation (i.e. update the original song_id) and then get a new value for song_id from the new song).

Yeah, I've return this on the code, don't kown why I don't keep
Reply
#63
(2023-02-07, 01:38)sagrath Wrote: The tempo of the music doesn't really matter. The song's tempo will always be divided into 11 equal parts, and then the note will be applied as soon as you play those parts.

That makes sense and should work fine.  I hadn't looked that closely at your calculations.  As long as it doesn't exceed 10, which is the maximum in the Kodi Music DB spec.  The database will handle a higher number but something greater than 10 might impact other Kodi code or addons.
 
Quote:Oh yes I will add back, the code I post it's not the Release code, only the final working code, now the logic is finished, I will now working to avoid possible errors, maybe not consider songs below "x" seconds, like the intro to the Offspring album Smash, which is only 26 seconds long... it would be silly (I think) to calculate a "song" like that. 
But if the album rating idea I mentioned before "works out", then even short songs should be calculated.

I think it makes sense to drop short tracks, say < 30 seconds or similar from getting a new userrating.  They could calculate a very high rating quickly.  For an album rating when you query the tracks you can filter the query to something like tracks where duration > 30 seconds or similar.  Then just count the number of tracks returned which meet your filter criteria.

One other thought, have you considered the number of times a track has been played (i.e. playcount) into the userrating calculation ?  Something like you could multiply the new userrating by playcount / 10 and once playcount is 10 multiply by1 or don't multiply at all.   Just a thought.


Thanks,

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
#64
Even before writing the code, using the playcount was my first idea, but I couldn't think of a precise way to rate the music. I took myself as an example, because I can't "grade" something, that's where this crazy idea of evaluating according to how much from the song is heard, and not how many times the music is played. But tell me more about your idea.

A doubt: The playcount increases at what time? Starting a song, and half playing it increases your score? Or only when the music plays to the end?
Reply
#65
(2023-02-07, 13:13)sagrath Wrote: Even before writing the code, using the playcount was my first idea, but I couldn't think of a precise way to rate the music. I took myself as an example, because I can't "grade" something, that's where this crazy idea of evaluating according to how much from the song is heard, and not how many times the music is played. But tell me more about your idea.

A doubt: The playcount increases at what time? Starting a song, and half playing it increases your score? Or only when the music plays to the end?

I am not sure on the playcount incrementing question.  That's a Kodi question.  I run Mezzmo, which syncs  the  Kodi database and Mezzmo allows setting a percentage of total playback time to increment the play counter.,  If you are going to go this route an option might be just to check the playcount on playback started to set a multiplier value (using my example).


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
#66
Hello!!! Good news!!!

Now the script check if song has an DBID from database. This way it will not get errors if an audio plays from file browser.
Another thing it's to On/Off three types of notifications:

When the song is started;
When the song gets a new rating;
The Real-time rating as song plays.

And last but not least, the option to stop auto-rating, this way the songs will not be rated (usefull when on a party, people skip songs over and over again)

And as it would be VERY difficult to reach these addon settings options, I learned how to create a context menu. Now when opening the context menu in the music section, you will have the option to open the addon settings.

I also made an art for the icon, and added a fanart. I think it turned out pretty. If anyone wants to test the addon is there.

Song Auto Rating (Release Candidate)

If someone test, please give me a feedback.
Reply
#67
Congrats on getting your script working.
Just to clarify for me, is the object to rate the song by defining its rating value as the proportion a song is listened through completion? In other words skipping a song early means i think it deserves a low rating.

I am trying to find a way to automatically set a default Kodi rating only when songs are imported. I think I should be able to use a portion of your script for this, but I'm very new.
Reply

Logout Mark Read Team Forum Stats Members Help
Help to set "UserRating" in a song using script0