Notify only on player stop / mark as watched
#1
Hi there,
I'm building an addon for a movie and tv shows watch list app called Flox and I'm trying to notify the user that the item was marked as seen. I'm using `xbmc.Monitor` with `xbmc.Player()` and `progress` but the user will see a notification when the progress time is bigger than 80%.
Is it possible to listen to user action just like Player.stop or when Kodi considers an item as watched?
Thanks for your help.
Reply
#2
(2024-09-16, 18:46)Simounet Wrote: Hi there,
I'm building an addon for a movie and tv shows watch list app called Flox and I'm trying to notify the user that the item was marked as seen. I'm using `xbmc.Monitor` with `xbmc.Player()` and `progress` but the user will see a notification when the progress time is bigger than 80%.
Is it possible to listen to user action just like Player.stop or when Kodi considers an item as watched?
Thanks for your help.

Yes.  You can see how I do it here.  There may be other options but this works for me to capture all the Kodi and user actions around playback.  You can leverage xbmc.Player().getVideoInfoTag() to get the playcount /watched status.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#3
Hi Jeff,
It looks very promising to my issue but I'm new to Kodi addon development. Is the `XBMCPlayer` class called by the `monitor` part? Tried to use the class with `player = XBMCPlayer()` but without any success.
Thanks a lot for your quick reply!
Reply
#4
(2024-09-16, 20:42)Simounet Wrote: Hi Jeff,
It looks very promising to my issue but I'm new to Kodi addon development. Is the `XBMCPlayer` class called by the `monitor` part? Tried to use the class with `player = XBMCPlayer()` but without any success.
Thanks a lot for your quick reply!

No, they are separate classes.  Monitor watches for actions.  Player is specific to player events.  Hence, I use both.  Monitor is an event driven loop to check periodically.  Player is immediate notification of a player status change.  This is why you see them both called separately on lines 114 and 116 in my Python file.  In my case I am passing the player status to monitor to then do some event.  If you only need player events then you could do without the monitor class but I suspect you need both.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#5
Ok, I get it. I tried something dummy like that without any success:

python:

import xbmc
from resources.lib.monitor import Monitor

xbmc.log("Flox: starting", xbmc.LOGDEBUG)

class XBMCPlayer(xbmc.Player):

    def onPlayBackStarted(self):
        xbmc.log(
            f"Flox: start", xbmc.LOGINFO)

    def onPlayBackPaused(self):
        xbmc.log(
            f"Flox: paused", xbmc.LOGINFO)

    def onPlayBackResumed(self):
        xbmc.log(
            f"Flox: resumed", xbmc.LOGINFO)

    def onPlayBackStopped(self):
        xbmc.log(
            f"Flox: stopped", xbmc.LOGINFO)

player = XBMCPlayer()



xbmc.log("Flox: exiting", xbmc.LOGDEBUG)
Reply
#6
(2024-09-16, 21:02)Simounet Wrote: Ok, I get it. I tried something dummy like that without any success:

With that code you should get log messages when player events occur but it is outside of the monitor class (i.e no monitor loop) so it will be event driven and not time driven.  I'd add importing the xbmcaddon class, just as standard good practice for addons.  I also am not fond of imports that are the same name as existing Kodi classes.

For example:

from resources.lib.monitor import Monitor

What is this Monitor import ?


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#7
It was pointing to that file. But I removed the import and same issue.
Reply
#8
(2024-09-16, 22:05)Simounet Wrote: It was pointing to that file. But I removed the import and same issue.

Let me see your addon.xml file. You may not be starting the service properly.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#9
Here it is.
Reply
#10
Seems like we always need a monitor. Here is a working sample:
python:
import xbmc
 
class XBMCPlayer( xbmc.Player ):
 
    def __init__( self, *args ):
        pass
        
    def onAVStarted(self):
        if self.isPlayingVideo():
            xbmc.log(f"Flox: STARTED", xbmc.LOGINFO)
 
    def onPlayBackPaused( self ):
        if self.isPlayingVideo():
            xbmc.log(f"Flox: PAUSED", xbmc.LOGINFO)
 
    def onPlayBackResumed( self ):
        if self.isPlayingVideo():
            xbmc.log(f"Flox: RESUMED", xbmc.LOGINFO)
            
    def onPlayBackStopped( self ):
        xbmc.log(f"Flox: STOPPED", xbmc.LOGINFO)
      
player = XBMCPlayer()
monitor = xbmc.Monitor()

while not monitor.abortRequested():
    if monitor.waitForAbort(1):
        break

I'll deep dive to try to make it work on mark as watched from the context menu.
Reply
#11
(2024-09-16, 22:25)Simounet Wrote: Here it is.

What specifically isn't working ?  I did a little debugging and got to the point where:

videoInfoTag = playingItem.getVideoInfoTag()

is working in your scrobbler.py file.  So the monitor and player classes are working.  I didn't try to figure out what the rest of the code is supposed to do.  You mentioned in the beginning about notifying the user.  I don't see any notifications in your code (i.e. xbmcgui.Dialog().notification(dialog_text, notification, icon, 5000)) etc...


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#12
(2024-09-16, 22:53)Simounet Wrote: I'll deep dive to try to make it work on mark as watched from the context menu.

That's more how I would do it and similar to what I originally provided.  You also went from 30 seconds in your monitor loop to 1 second, which should help.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#13
It's the notification about "marked as watched" that bothers me. With the monitoring stuff, I'll see the notifications at 80% of progress while I'm still watching the movie. I need to split the action in two parts. Still using monitoring to send the API request to mark the item as watched in Flox, then using the player stop action to notify the user about the response.
Reply
#14
(2024-09-17, 08:23)Simounet Wrote:
XML:
It's the notification about "marked as watched" that bothers me. With the monitoring stuff, I'll see the notifications at 80% of progress while I'm still watching the movie. I need to split the action in two parts. Still using monitoring to send the API request to mark the item as watched in Flox, then using the player stop action to notify the user about the response.

You might still want to break it into separate actions, but you can change the percentage watched that will trigger the mark as watched notification.  Add this to your advanced settings:

Code:
<playcountminimumpercent>90</playcountminimumpercent>

Just a note that if you set it to 100%, you have to play the video absolutely all the way to the end for it to be marked as watched.

More info on that setting at:

https://kodi.wiki/view/Advancedsettings.xml#video
Reply
#15
Thanks a lot for your reply. I don't want to bother the user with notification while still playing the item. That's why I was trying to use the onPlayBackStopped event.
Reply

Logout Mark Read Team Forum Stats Members Help
Notify only on player stop / mark as watched0