Account for changing transcode decisions from websocket events

This commit is contained in:
samwiseg00 2018-10-05 23:16:49 -04:00
parent a94207691f
commit df76a02478

View file

@ -184,6 +184,19 @@ class ActivityHandler(object):
plexpy.NOTIFY_QUEUE.put({'stream_data': db_session.copy(), 'notify_action': 'on_resume'}) plexpy.NOTIFY_QUEUE.put({'stream_data': db_session.copy(), 'notify_action': 'on_resume'})
def on_change(self):
if self.is_valid_session():
logger.debug(u"Tautulli ActivityHandler :: Session %s has changed transcode decision." % str(self.get_session_key()))
# Update the session state and viewOffset
self.update_db_session()
# Retrieve the session data from our temp table
ap = activity_processor.ActivityProcessor()
db_session = ap.get_session_by_key(session_key=self.get_session_key())
plexpy.NOTIFY_QUEUE.put({'stream_data': db_session.copy(), 'notify_action': 'on_change'})
def on_buffer(self): def on_buffer(self):
if self.is_valid_session(): if self.is_valid_session():
logger.debug(u"Tautulli ActivityHandler :: Session %s is buffering." % self.get_session_key()) logger.debug(u"Tautulli ActivityHandler :: Session %s is buffering." % self.get_session_key())
@ -228,6 +241,7 @@ class ActivityHandler(object):
this_state = self.timeline['state'] this_state = self.timeline['state']
this_rating_key = str(self.timeline['ratingKey']) this_rating_key = str(self.timeline['ratingKey'])
this_key = self.timeline['key'] this_key = self.timeline['key']
this_transcode_key = self.timeline.get('transcodeSession', '')
# Get the live tv session uuid # Get the live tv session uuid
this_live_uuid = this_key.split('/')[-1] if this_key.startswith('/livetv/sessions') else None this_live_uuid = this_key.split('/')[-1] if this_key.startswith('/livetv/sessions') else None
@ -241,6 +255,7 @@ class ActivityHandler(object):
last_state = db_session['state'] last_state = db_session['state']
last_rating_key = str(db_session['rating_key']) last_rating_key = str(db_session['rating_key'])
last_live_uuid = db_session['live_uuid'] last_live_uuid = db_session['live_uuid']
last_transcode_key = db_session['transcode_key'].split('/')[-1]
# Make sure the same item is being played # Make sure the same item is being played
if this_rating_key == last_rating_key or this_live_uuid == last_live_uuid: if this_rating_key == last_rating_key or this_live_uuid == last_live_uuid:
@ -267,6 +282,9 @@ class ActivityHandler(object):
# Update the session last_paused timestamp # Update the session last_paused timestamp
self.on_pause(still_paused=True) self.on_pause(still_paused=True)
if this_transcode_key != last_transcode_key and this_state != 'buffering':
self.on_change()
# If a client doesn't register stop events (I'm looking at you PHT!) check if the ratingKey has changed # If a client doesn't register stop events (I'm looking at you PHT!) check if the ratingKey has changed
else: else:
# Manually stop and start # Manually stop and start