2016-01-08, 11:23
Hello. I want to detect the movie has been watched (mark as watched) )when playback stop.
I have script service with onPlayBackStopped and onPlayBackStarted methods.
When I press stop button KODI run onPlayBackStop function before it makes changes in database. I must wait a while to get updated playcount. This time maybe different on different PC.
Maybe is a simpler way to check that playcount is increased?
I have script service with onPlayBackStopped and onPlayBackStarted methods.
Code:
class Player(xbmc.Player):
def __init__(self):
xbmc.Player.__init__(self)
def onPlayBackStarted(self):
jsonGet = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "params": {"playerid": 1}, "method": "Player.GetItem", "id": 1}')
jsonGetResponse = json.loads(unicode(jsonGet, 'utf-8', errors='ignore'))
self.movieid = str(jsonGetResponse['result']['item']['id'])
jsonGet = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"movieid": ' + self.movieid + ', "properties": ["playcount"]}, "id": 1}')
jsonGetResponse = json.loads(unicode(jsonGet, 'utf-8', errors='ignore'))
playcount = jsonGetResponse['result']['moviedetails']['playcount']
print "onPlayback: " + str(playcount)
def onPlayBackStopped(self):
jsonGet = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"movieid": ' + self.movieid + ', "properties": ["playcount"]}, "id": 1}')
jsonGetResponse = json.loads(unicode(jsonGet, 'utf-8', errors='ignore'))
playcount = jsonGetResponse['result']['moviedetails']['playcount']
print "onStop: " + str(playcount)
xbmc.sleep(1000)
jsonGet = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"movieid": ' + self.movieid + ', "properties": ["playcount"]}, "id": 1}')
jsonGetResponse = json.loads(unicode(jsonGet, 'utf-8', errors='ignore'))
playcount = jsonGetResponse['result']['moviedetails']['playcount']
print "onStopAfterSleep: " + str(playcount)
player = Player()
while(not xbmc.abortRequested):
xbmc.sleep(500)
When I press stop button KODI run onPlayBackStop function before it makes changes in database. I must wait a while to get updated playcount. This time maybe different on different PC.
Maybe is a simpler way to check that playcount is increased?
Code:
10:15:10 T:7804 NOTICE: onPlayback: 5
10:15:13 T:7804 NOTICE: onStop: 5
10:15:14 T:2912 DEBUG: Mysql execute: update files set playCount=6,lastPlayed='2016-01-08 10:15:14' where idFile=494
10:15:14 T:7804 NOTICE: onStopAfterSleep: 6