mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 06:13:25 -07:00
Change to notify stopped only if less than watched percent
* Also fix paused notifications sending at the end of items (right before stopping)
This commit is contained in:
parent
f7bc208fd1
commit
3f56bedcc6
2 changed files with 38 additions and 31 deletions
|
@ -1,4 +1,4 @@
|
||||||
# This file is part of PlexPy.
|
# This file is part of PlexPy.
|
||||||
#
|
#
|
||||||
# PlexPy is free software: you can redistribute it and/or modify
|
# PlexPy is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -178,6 +178,13 @@ class ActivityHandler(object):
|
||||||
last_state = db_session['state']
|
last_state = db_session['state']
|
||||||
last_key = str(db_session['rating_key'])
|
last_key = str(db_session['rating_key'])
|
||||||
|
|
||||||
|
# Monitor if the stream has reached the watch percentage for notifications
|
||||||
|
# The only purpose of this is for notifications
|
||||||
|
progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration'])
|
||||||
|
if progress_percent >= plexpy.CONFIG.NOTIFY_WATCHED_PERCENT and this_state != 'buffering':
|
||||||
|
threading.Thread(target=notification_handler.notify,
|
||||||
|
kwargs=dict(stream_data=db_session, notify_action='watched')).start()
|
||||||
|
|
||||||
# Make sure the same item is being played
|
# Make sure the same item is being played
|
||||||
if this_key == last_key:
|
if this_key == last_key:
|
||||||
# Update the session state and viewOffset
|
# Update the session state and viewOffset
|
||||||
|
@ -187,11 +194,11 @@ class ActivityHandler(object):
|
||||||
view_offset=self.timeline['viewOffset'])
|
view_offset=self.timeline['viewOffset'])
|
||||||
# Start our state checks
|
# Start our state checks
|
||||||
if this_state != last_state:
|
if this_state != last_state:
|
||||||
if this_state == 'paused':
|
if this_state == 'paused' and progress_percent < 99:
|
||||||
self.on_pause()
|
self.on_pause()
|
||||||
elif last_state == 'paused' and this_state == 'playing':
|
elif last_state == 'paused' and this_state == 'playing' and progress_percent < 99:
|
||||||
self.on_resume()
|
self.on_resume()
|
||||||
elif this_state == 'stopped':
|
elif this_state == 'stopped' and progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
||||||
self.on_stop()
|
self.on_stop()
|
||||||
elif this_state == 'buffering':
|
elif this_state == 'buffering':
|
||||||
self.on_buffer()
|
self.on_buffer()
|
||||||
|
@ -202,13 +209,6 @@ class ActivityHandler(object):
|
||||||
self.on_stop(force_stop=True)
|
self.on_stop(force_stop=True)
|
||||||
self.on_start()
|
self.on_start()
|
||||||
|
|
||||||
# Monitor if the stream has reached the watch percentage for notifications
|
|
||||||
# The only purpose of this is for notifications
|
|
||||||
progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration'])
|
|
||||||
if progress_percent >= plexpy.CONFIG.NOTIFY_WATCHED_PERCENT and this_state != 'buffering':
|
|
||||||
threading.Thread(target=notification_handler.notify,
|
|
||||||
kwargs=dict(stream_data=db_session, notify_action='watched')).start()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# We don't have this session in our table yet, start a new one.
|
# We don't have this session in our table yet, start a new one.
|
||||||
if this_state != 'buffering':
|
if this_state != 'buffering':
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# This file is part of PlexPy.
|
# This file is part of PlexPy.
|
||||||
#
|
#
|
||||||
# PlexPy is free software: you can redistribute it and/or modify
|
# PlexPy is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -48,6 +48,12 @@ def check_active_sessions(ws_request=False):
|
||||||
for stream in db_streams:
|
for stream in db_streams:
|
||||||
if any(d['session_key'] == str(stream['session_key']) and d['rating_key'] == str(stream['rating_key'])
|
if any(d['session_key'] == str(stream['session_key']) and d['rating_key'] == str(stream['rating_key'])
|
||||||
for d in media_container):
|
for d in media_container):
|
||||||
|
|
||||||
|
if stream['view_offset'] and stream['duration']:
|
||||||
|
progress_percent = helpers.get_percent(stream['view_offset'], stream['duration'])
|
||||||
|
else:
|
||||||
|
progress_percent = None
|
||||||
|
|
||||||
# The user's session is still active
|
# The user's session is still active
|
||||||
for session in media_container:
|
for session in media_container:
|
||||||
if session['session_key'] == str(stream['session_key']) and \
|
if session['session_key'] == str(stream['session_key']) and \
|
||||||
|
@ -55,13 +61,13 @@ def check_active_sessions(ws_request=False):
|
||||||
# The user is still playing the same media item
|
# The user is still playing the same media item
|
||||||
# Here we can check the play states
|
# Here we can check the play states
|
||||||
if session['state'] != stream['state']:
|
if session['state'] != stream['state']:
|
||||||
if session['state'] == 'paused':
|
if session['state'] == 'paused' and progress_percent < 99:
|
||||||
# Push any notifications -
|
# Push any notifications -
|
||||||
# Push it on it's own thread so we don't hold up our db actions
|
# Push it on it's own thread so we don't hold up our db actions
|
||||||
threading.Thread(target=notification_handler.notify,
|
threading.Thread(target=notification_handler.notify,
|
||||||
kwargs=dict(stream_data=stream, notify_action='pause')).start()
|
kwargs=dict(stream_data=stream, notify_action='pause')).start()
|
||||||
|
|
||||||
if session['state'] == 'playing' and stream['state'] == 'paused':
|
if session['state'] == 'playing' and stream['state'] == 'paused' and progress_percent < 99:
|
||||||
# Push any notifications -
|
# Push any notifications -
|
||||||
# Push it on it's own thread so we don't hold up our db actions
|
# Push it on it's own thread so we don't hold up our db actions
|
||||||
threading.Thread(target=notification_handler.notify,
|
threading.Thread(target=notification_handler.notify,
|
||||||
|
@ -126,9 +132,7 @@ def check_active_sessions(ws_request=False):
|
||||||
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
||||||
# Don't trigger if state is buffer as some clients push the progress to the end when
|
# Don't trigger if state is buffer as some clients push the progress to the end when
|
||||||
# buffering on start.
|
# buffering on start.
|
||||||
if session['view_offset'] and session['duration'] and session['state'] != 'buffering':
|
if progress_percent > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT and session['state'] != 'buffering':
|
||||||
if helpers.get_percent(session['view_offset'],
|
|
||||||
session['duration']) > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
|
||||||
# Push any notifications -
|
# Push any notifications -
|
||||||
# Push it on it's own thread so we don't hold up our db actions
|
# Push it on it's own thread so we don't hold up our db actions
|
||||||
threading.Thread(target=notification_handler.notify,
|
threading.Thread(target=notification_handler.notify,
|
||||||
|
@ -141,15 +145,18 @@ def check_active_sessions(ws_request=False):
|
||||||
monitor_db.action('DELETE FROM sessions WHERE session_key = ? AND rating_key = ?',
|
monitor_db.action('DELETE FROM sessions WHERE session_key = ? AND rating_key = ?',
|
||||||
[stream['session_key'], stream['rating_key']])
|
[stream['session_key'], stream['rating_key']])
|
||||||
|
|
||||||
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
|
||||||
if stream['view_offset'] and stream['duration']:
|
if stream['view_offset'] and stream['duration']:
|
||||||
if helpers.get_percent(stream['view_offset'],
|
progress_percent = helpers.get_percent(stream['view_offset'], stream['duration'])
|
||||||
stream['duration']) > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
else:
|
||||||
|
progress_percent = None
|
||||||
|
|
||||||
|
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
||||||
|
if progress_percent > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
||||||
# Push any notifications -
|
# Push any notifications -
|
||||||
# Push it on it's own thread so we don't hold up our db actions
|
# Push it on it's own thread so we don't hold up our db actions
|
||||||
threading.Thread(target=notification_handler.notify,
|
threading.Thread(target=notification_handler.notify,
|
||||||
kwargs=dict(stream_data=stream, notify_action='watched')).start()
|
kwargs=dict(stream_data=stream, notify_action='watched')).start()
|
||||||
|
else:
|
||||||
# Push any notifications - Push it on it's own thread so we don't hold up our db actions
|
# Push any notifications - Push it on it's own thread so we don't hold up our db actions
|
||||||
threading.Thread(target=notification_handler.notify,
|
threading.Thread(target=notification_handler.notify,
|
||||||
kwargs=dict(stream_data=stream, notify_action='stop')).start()
|
kwargs=dict(stream_data=stream, notify_action='stop')).start()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue