mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 06:13:25 -07:00
Fix code to only affect notifications
This commit is contained in:
parent
fcbf82c6e0
commit
138dd61e51
1 changed files with 28 additions and 16 deletions
|
@ -66,6 +66,8 @@ class ActivityHandler(object):
|
||||||
|
|
||||||
def on_stop(self, force_stop=False):
|
def on_stop(self, force_stop=False):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
|
from plexpy import helpers
|
||||||
|
|
||||||
logger.debug(u"PlexPy ActivityHandler :: Session %s has stopped." % str(self.get_session_key()))
|
logger.debug(u"PlexPy ActivityHandler :: Session %s has stopped." % str(self.get_session_key()))
|
||||||
|
|
||||||
# Set the session last_paused timestamp
|
# Set the session last_paused timestamp
|
||||||
|
@ -83,8 +85,10 @@ class ActivityHandler(object):
|
||||||
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
||||||
|
|
||||||
# Fire off notifications
|
# Fire off notifications
|
||||||
threading.Thread(target=notification_handler.notify,
|
progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration'])
|
||||||
kwargs=dict(stream_data=db_session, notify_action='stop')).start()
|
if progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
||||||
|
threading.Thread(target=notification_handler.notify,
|
||||||
|
kwargs=dict(stream_data=db_session, notify_action='stop')).start()
|
||||||
|
|
||||||
# Write it to the history table
|
# Write it to the history table
|
||||||
monitor_proc = activity_processor.ActivityProcessor()
|
monitor_proc = activity_processor.ActivityProcessor()
|
||||||
|
@ -95,6 +99,8 @@ class ActivityHandler(object):
|
||||||
|
|
||||||
def on_pause(self):
|
def on_pause(self):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
|
from plexpy import helpers
|
||||||
|
|
||||||
logger.debug(u"PlexPy ActivityHandler :: Session %s has been paused." % str(self.get_session_key()))
|
logger.debug(u"PlexPy ActivityHandler :: Session %s has been paused." % str(self.get_session_key()))
|
||||||
|
|
||||||
# Set the session last_paused timestamp
|
# Set the session last_paused timestamp
|
||||||
|
@ -110,11 +116,15 @@ class ActivityHandler(object):
|
||||||
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
||||||
|
|
||||||
# Fire off notifications
|
# Fire off notifications
|
||||||
threading.Thread(target=notification_handler.notify,
|
progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration'])
|
||||||
kwargs=dict(stream_data=db_session, notify_action='pause')).start()
|
if progress_percent < 99:
|
||||||
|
threading.Thread(target=notification_handler.notify,
|
||||||
|
kwargs=dict(stream_data=db_session, notify_action='pause')).start()
|
||||||
|
|
||||||
def on_resume(self):
|
def on_resume(self):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
|
from plexpy import helpers
|
||||||
|
|
||||||
logger.debug(u"PlexPy ActivityHandler :: Session %s has been resumed." % str(self.get_session_key()))
|
logger.debug(u"PlexPy ActivityHandler :: Session %s has been resumed." % str(self.get_session_key()))
|
||||||
|
|
||||||
# Set the session last_paused timestamp
|
# Set the session last_paused timestamp
|
||||||
|
@ -130,8 +140,10 @@ class ActivityHandler(object):
|
||||||
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
||||||
|
|
||||||
# Fire off notifications
|
# Fire off notifications
|
||||||
threading.Thread(target=notification_handler.notify,
|
progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration'])
|
||||||
kwargs=dict(stream_data=db_session, notify_action='resume')).start()
|
if progress_percent < 99:
|
||||||
|
threading.Thread(target=notification_handler.notify,
|
||||||
|
kwargs=dict(stream_data=db_session, notify_action='resume')).start()
|
||||||
|
|
||||||
def on_buffer(self):
|
def on_buffer(self):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
|
@ -178,13 +190,6 @@ 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
|
||||||
|
@ -194,11 +199,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' and progress_percent < 99:
|
if this_state == 'paused':
|
||||||
self.on_pause()
|
self.on_pause()
|
||||||
elif last_state == 'paused' and this_state == 'playing' and progress_percent < 99:
|
elif last_state == 'paused' and this_state == 'playing':
|
||||||
self.on_resume()
|
self.on_resume()
|
||||||
elif this_state == 'stopped' and progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
elif this_state == 'stopped':
|
||||||
self.on_stop()
|
self.on_stop()
|
||||||
elif this_state == 'buffering':
|
elif this_state == 'buffering':
|
||||||
self.on_buffer()
|
self.on_buffer()
|
||||||
|
@ -209,6 +214,13 @@ 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':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue