From df76a02478ffa32e042363f37f47c8afaf08a0f8 Mon Sep 17 00:00:00 2001 From: samwiseg00 Date: Fri, 5 Oct 2018 23:16:49 -0400 Subject: [PATCH] Account for changing transcode decisions from websocket events --- plexpy/activity_handler.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plexpy/activity_handler.py b/plexpy/activity_handler.py index 735d47f7..2922eecf 100644 --- a/plexpy/activity_handler.py +++ b/plexpy/activity_handler.py @@ -184,6 +184,19 @@ class ActivityHandler(object): 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): if self.is_valid_session(): 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_rating_key = str(self.timeline['ratingKey']) this_key = self.timeline['key'] + this_transcode_key = self.timeline.get('transcodeSession', '') # Get the live tv session uuid 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_rating_key = str(db_session['rating_key']) last_live_uuid = db_session['live_uuid'] + last_transcode_key = db_session['transcode_key'].split('/')[-1] # Make sure the same item is being played 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 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 else: # Manually stop and start