mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 06:00:51 -07:00
Hack things to make sure we know what is going on when clients don't send a stop event.
This commit is contained in:
parent
74e8d7d329
commit
9fdcc93e2e
2 changed files with 34 additions and 16 deletions
|
@ -395,7 +395,7 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="monitoring_use_websocket" name="monitoring_use_websocket" value="1" ${config['monitoring_use_websocket']}> Use Websocket (requires restart)
|
<input type="checkbox" id="monitoring_use_websocket" name="monitoring_use_websocket" value="1" ${config['monitoring_use_websocket']}> Use Websocket (requires restart)
|
||||||
</label>
|
</label>
|
||||||
<p class="help-block">Instead of polling the server at regular intervals let the server tell us when something happens. This is currently experimental.</p>
|
<p class="help-block">Instead of polling the server at regular intervals let the server tell us when something happens. This is currently experimental. Encrypted websocket is not currently supported.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="padded-header">
|
<div class="padded-header">
|
||||||
|
|
|
@ -23,6 +23,7 @@ class ActivityHandler(object):
|
||||||
|
|
||||||
def __init__(self, timeline):
|
def __init__(self, timeline):
|
||||||
self.timeline = timeline
|
self.timeline = timeline
|
||||||
|
# print timeline
|
||||||
|
|
||||||
def is_valid_session(self):
|
def is_valid_session(self):
|
||||||
if 'sessionKey' in self.timeline:
|
if 'sessionKey' in self.timeline:
|
||||||
|
@ -63,7 +64,7 @@ class ActivityHandler(object):
|
||||||
# Write the new session to our temp session table
|
# Write the new session to our temp session table
|
||||||
self.update_db_session()
|
self.update_db_session()
|
||||||
|
|
||||||
def on_stop(self):
|
def on_stop(self, force_stop=False):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
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()))
|
||||||
|
|
||||||
|
@ -72,9 +73,11 @@ class ActivityHandler(object):
|
||||||
ap.set_session_last_paused(session_key=self.get_session_key(), timestamp=None)
|
ap.set_session_last_paused(session_key=self.get_session_key(), timestamp=None)
|
||||||
|
|
||||||
# Update the session state and viewOffset
|
# Update the session state and viewOffset
|
||||||
ap.set_session_state(session_key=self.get_session_key(),
|
# Set force_stop to true to disable the state set
|
||||||
state=self.timeline['state'],
|
if not force_stop:
|
||||||
view_offset=self.timeline['viewOffset'])
|
ap.set_session_state(session_key=self.get_session_key(),
|
||||||
|
state=self.timeline['state'],
|
||||||
|
view_offset=self.timeline['viewOffset'])
|
||||||
|
|
||||||
# Retrieve the session data from our temp table
|
# Retrieve the session data from our temp table
|
||||||
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())
|
||||||
|
@ -110,7 +113,7 @@ class ActivityHandler(object):
|
||||||
threading.Thread(target=notification_handler.notify,
|
threading.Thread(target=notification_handler.notify,
|
||||||
kwargs=dict(stream_data=db_session, notify_action='pause')).start()
|
kwargs=dict(stream_data=db_session, notify_action='pause')).start()
|
||||||
|
|
||||||
def on_resume(self, time_line=None):
|
def on_resume(self):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
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()))
|
||||||
|
|
||||||
|
@ -171,17 +174,32 @@ class ActivityHandler(object):
|
||||||
if db_session:
|
if db_session:
|
||||||
this_state = self.timeline['state']
|
this_state = self.timeline['state']
|
||||||
last_state = db_session['state']
|
last_state = db_session['state']
|
||||||
|
this_key = str(self.timeline['ratingKey'])
|
||||||
|
last_key = str(db_session['rating_key'])
|
||||||
|
|
||||||
# Start our state checks
|
# Make sure the same item is being played
|
||||||
if this_state != last_state:
|
if this_key == last_key:
|
||||||
if this_state == 'paused':
|
# Update the session state and viewOffset
|
||||||
self.on_pause()
|
if this_state == 'playing':
|
||||||
elif last_state == 'paused' and this_state == 'playing':
|
ap.set_session_state(session_key=self.get_session_key(),
|
||||||
self.on_resume()
|
state=this_state,
|
||||||
elif this_state == 'stopped':
|
view_offset=self.timeline['viewOffset'])
|
||||||
self.on_stop()
|
# Start our state checks
|
||||||
elif this_state == 'buffering':
|
if this_state != last_state:
|
||||||
self.on_buffer()
|
if this_state == 'paused':
|
||||||
|
self.on_pause()
|
||||||
|
elif last_state == 'paused' and this_state == 'playing':
|
||||||
|
self.on_resume()
|
||||||
|
elif this_state == 'stopped':
|
||||||
|
self.on_stop()
|
||||||
|
elif this_state == 'buffering':
|
||||||
|
self.on_buffer()
|
||||||
|
# If a client doesn't register stop events (I'm looking at you PHT!) check if the ratingKey has changed
|
||||||
|
else:
|
||||||
|
# Manually stop and start
|
||||||
|
# Set force_stop so that we don't overwrite our last viewOffset
|
||||||
|
self.on_stop(force_stop=True)
|
||||||
|
self.on_start()
|
||||||
|
|
||||||
# Monitor if the stream has reached the watch percentage for notifications
|
# Monitor if the stream has reached the watch percentage for notifications
|
||||||
# The only purpose of this is for notifications
|
# The only purpose of this is for notifications
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue