perform action when a video is watched

  Thread Rating:
  • 2 Votes - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
damonbrodie Offline
Junior Member
Posts: 38
Joined: May 2014
Reputation: 0
Post: #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
find quote
Martijn Offline
Team Kodi
Posts: 11,202
Joined: Jul 2011
Reputation: 162
Location: Dawn of time
Post: #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.

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
(This post was last modified: 2014-05-02 20:32 by Martijn.)
find quote
damonbrodie Offline
Junior Member
Posts: 38
Joined: May 2014
Reputation: 0
Post: #3
Martijn,

That's perfect - exactly what I needed!
find quote
damonbrodie Offline
Junior Member
Posts: 38
Joined: May 2014
Reputation: 0
Post: #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?
find quote
Martijn Offline
Team Kodi
Posts: 11,202
Joined: Jul 2011
Reputation: 162
Location: Dawn of time
Post: #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

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
(This post was last modified: 2014-05-02 21:06 by Martijn.)
find quote
damonbrodie Offline
Junior Member
Posts: 38
Joined: May 2014
Reputation: 0
Post: #6
Looks like a much cleaner way is for the add-on to simply capture the VideoLibrary.OnUpdate json notifications.
find quote
damonbrodie Offline
Junior Member
Posts: 38
Joined: May 2014
Reputation: 0
Post: #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
find quote
damonbrodie Offline
Junior Member
Posts: 38
Joined: May 2014
Reputation: 0
Post: #8
Answering this myself for future searches. onDatabaseUpdated does not run when the playcount (watched) is incremented. At least not in Frodo.
find quote
4lb3rtO Offline
Junior Member
Posts: 6
Joined: Nov 2013
Reputation: 0
Location: Germany
Post: #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
find quote
damonbrodie Offline
Junior Member
Posts: 38
Joined: May 2014
Reputation: 0
Post: #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
find quote