perform action when a video is watched
#1
Hi,

I'd like to perform an action on a remote server then a video is mark watched. I've written python before - looks straightforward to write an addon.

So it looks to me like the right way is to subclass the player, and take action on onplaybackstopped. From there, figure out what video was just being watched, and then check the database to see if the watched flag is set (i.e. the user watched the video to the end and now the watched flag is set.

Does this sound like the right path forward, or is there a better way to do this?

Thanks!

Damon
Reply
#2
sounds right

example
https://github.com/XBMC-Addons/service.s...lt.py#L249

onPlayBackEnded and onPlayBackStopped are separate so should tell you if they actually finished it.
if playback was stopped at ~90% (or something) it will still mark it as watched.
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#3
Martijn,

That's perfect - exactly what I needed!
Reply
#4
Looking at the infotagvideo I don't see the watched status among the listed elements (but lastplayed is there). Is the watched flag stored elsewhere?
Reply
#5
you need to do a JSON-RPC request to get that. as you have last played you can easily get the specifics for that video
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#6
Looks like a much cleaner way is for the add-on to simply capture the VideoLibrary.OnUpdate json notifications.
Reply
#7
This is the code I have for subclassing Monitor. Any ideas why this doesn't work?

Similar code worked for subclassing Player.

PHP Code:
import xbmc
import xbmcaddon

__addon__      
xbmcaddon.Addon()

class 
XBMCMonitorxbmc.Monitor ):

    
def __init__self, *args ):
        
pass

    def onDatabaseUpdated
(selfdatabase):
        
xbmc.sleep(1000)
        
xbmc.log"GOTCHA" )

monitor XBMCMonitor()

while(
not xbmc.abortRequested):
    
xbmc.sleep(100
Reply
#8
Answering this myself for future searches. onDatabaseUpdated does not run when the playcount (watched) is incremented. At least not in Frodo.
Reply
#9
onDatabaseUpdated will only be called when database gets updated and the DB has been changed.
You can do this with the json notification VideoLibrary.OnUpdate and a tcp connection to xbmc's json port (default 9090). Then you can receive a notification when the watchedstate has been changed (maually/automatically) in xbmc

You can find an example for the tcp connection in the repository of the german community xbmcnerds
http://www.xbmcnerds.com/index.php?page=...dataID=100
in the service.nfo.watchedstate.updater addon

This addon writes the current watchedstate into the nfo files when the watchedstate has been changed in xbmc. Ok, this is not exactly what you are looking for, but the approach is the same
Reply
#10
And this is even easier in 13. There is a new Monitor.onNotification you can use. This is the code I ended up with:

PHP Code:
import xbmc

class XBMCMonitorxbmc.Monitor ):

    
def onNotification(selfsendermethoddata):
        if (
method == 'VideoLibrary.OnUpdate'):
            
response json.loads(data)          
            if (
response.has_key('item') and response['item'].has_key('type') and response.get('item').get('type') == 'episode'): 
                
episodeid response.get('item').get('id')
                
playcount response.get('playcount')

monitor XBMCMonitor()

while(
not xbmc.abortRequested):
    
xbmc.sleep(100
Reply

Logout Mark Read Team Forum Stats Members Help
perform action when a video is watched2