onPlayBackStopped - detect watched
#1
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.

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
Reply
#2
Using a xbmc.Monitor and watching for 'Player.OnStop' in onNotification is another option. It has a bit of data right in it to tell you if the video was played all the way through.

Code:
def onNotification(self, sender, method, data):
    if method == 'Player.OnStop':
        data = json.loads(data)
        watched_to_end = data['end']

If you need to do something after the database has been updated, stash the item info from 'Player.OnStop', watch for 'VideoLibrary.OnUpdate' and grab its item info, and if they match you can be sure the database has been updated, and that OnUpdate wasn't from some other action.
Reply
#3
Thx, onNotification and VideoLibrary.OnUpdate do the job. When placount is updated it show in JSON.
Reply

Logout Mark Read Team Forum Stats Members Help
onPlayBackStopped - detect watched1