2023-01-24, 16:04
Hello everybody! How are you?
I come here to explore an idea I had, and also ask for help.
A while ago I had the idea of creating a script to "auto-rating" songs from the Kodi library.
The idea is to divide the music time into 11 parts, classifying them from "0" to "10". This way the music is being "rated" while it is played.
Why divide the songs in "11" parts?
Because 1/11 part is = "0", 2/11 = "1", 3/11= "2" .... 9/11 = "8", 10/11 = "09", 11/11 = "10"
this way, a song with 4:21 (4 minutes and 21 seconds) has 261 seconds, and each part has almost "24" seconds (24*11 = 264)
This is just the general idea, as I still want to implement a grade summing system. But for that I need this code to work correctly:
edit:
here an image with the script "working"
The notification shows an "8" of rating.
As you can see, the values are calculated correctly, I'm just having difficulty saving the value of "rating" and bringing the value of the variable "time_parts" into "monitor.waitForAbort(time_parts)" Does anyone have this answer?
Thanks in Advance
I come here to explore an idea I had, and also ask for help.
A while ago I had the idea of creating a script to "auto-rating" songs from the Kodi library.
The idea is to divide the music time into 11 parts, classifying them from "0" to "10". This way the music is being "rated" while it is played.
Why divide the songs in "11" parts?
Because 1/11 part is = "0", 2/11 = "1", 3/11= "2" .... 9/11 = "8", 10/11 = "09", 11/11 = "10"
this way, a song with 4:21 (4 minutes and 21 seconds) has 261 seconds, and each part has almost "24" seconds (24*11 = 264)
This is just the general idea, as I still want to implement a grade summing system. But for that I need this code to work correctly:
Code:
# Execute on Kodi Start-Up and wait for the song be played
import xbmc
import xbmcaddon
ADDON = xbmcaddon.Addon()
ADDON_PATH = ADDON.getAddonInfo('path')
monitor = xbmc.Monitor()
player = xbmc.Player()
def onPlayBackEnded():
xbmc.executebuiltin("Notification(Song ended, The song has ended)")
xbmc.executebuiltin("PlayerControl(SetUserRating, %s)" % rating)
player.onPlayBackEnded(onPlayBackEnded)
while not monitor.abortRequested():
if player.isPlaying():
# get all the needed times info from the song
song = player.getMusicInfoTag()
song_length = song.getDuration()
time_parts = song_length/11
current_time = player.getTime()
# calculate the rating as the music is played
rating = int(current_time/time_parts)
# Here I need to find out how to set the Rating of the music.
# song.setUserRating(rating) and song.setRating(rating) appears not working, because the rating in SongInformation Window not change.
#This notification is only to "see" the script working
xbmc.executebuiltin("Notification(%s, %s)" % ("Rating",song.getUserRating()))
# the value of 10 is arbitrary. The ideal would be to use the same value of "time_parts", but I haven't figured out how to bring this variable from within the "if player.isPlaying(): "
monitor.waitForAbort(10)
edit:
here an image with the script "working"
The notification shows an "8" of rating.
As you can see, the values are calculated correctly, I'm just having difficulty saving the value of "rating" and bringing the value of the variable "time_parts" into "monitor.waitForAbort(time_parts)" Does anyone have this answer?
Thanks in Advance