From af3944734f8f07aa39a1a12a043addcdf03dd9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20B=C3=B6hm?= Date: Thu, 20 Sep 2018 01:13:31 +0200 Subject: [PATCH 1/2] Fix for usage of wrong view offset field when serializing to session_history Also add code to update view offset in sessions table more often --- plexpy/activity_handler.py | 6 ++++++ plexpy/activity_processor.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plexpy/activity_handler.py b/plexpy/activity_handler.py index 735d47f7..66540eb6 100644 --- a/plexpy/activity_handler.py +++ b/plexpy/activity_handler.py @@ -228,6 +228,7 @@ class ActivityHandler(object): this_state = self.timeline['state'] this_rating_key = str(self.timeline['ratingKey']) this_key = self.timeline['key'] + this_view_offset = self.timeline['viewOffset'] # Get the live tv session uuid this_live_uuid = this_key.split('/')[-1] if this_key.startswith('/livetv/sessions') else None @@ -241,6 +242,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_view_offset = db_session['view_offset'] # Make sure the same item is being played if this_rating_key == last_rating_key or this_live_uuid == last_live_uuid: @@ -251,6 +253,10 @@ class ActivityHandler(object): if int(time.time()) - db_session['stopped'] > 60: self.update_db_session() + # Update db session when view offset changes + if this_view_offset != last_view_offset: + self.update_db_session() + # Start our state checks if this_state != last_state: if this_state == 'paused': diff --git a/plexpy/activity_processor.py b/plexpy/activity_processor.py index 5bb0041f..eba77c68 100644 --- a/plexpy/activity_processor.py +++ b/plexpy/activity_processor.py @@ -156,10 +156,11 @@ class ActivityProcessor(object): # Reload json from raw stream info if session.get('raw_stream_info'): raw_stream_info = json.loads(session['raw_stream_info']) - # Don't overwrite id, session_key, stopped + # Don't overwrite id, session_key, stopped, view_offset raw_stream_info.pop('id', None) raw_stream_info.pop('session_key', None) raw_stream_info.pop('stopped', None) + raw_stream_info.pop('view_offset', None) session.update(raw_stream_info) session = defaultdict(str, session) From 40559471cfb39d293bf3d19bcd9db8bd62b31ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20B=C3=B6hm?= Date: Sat, 6 Oct 2018 11:01:13 +0200 Subject: [PATCH 2/2] Remove code to update view offset for every websocket event --- plexpy/activity_handler.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plexpy/activity_handler.py b/plexpy/activity_handler.py index 66540eb6..735d47f7 100644 --- a/plexpy/activity_handler.py +++ b/plexpy/activity_handler.py @@ -228,7 +228,6 @@ class ActivityHandler(object): this_state = self.timeline['state'] this_rating_key = str(self.timeline['ratingKey']) this_key = self.timeline['key'] - this_view_offset = self.timeline['viewOffset'] # Get the live tv session uuid this_live_uuid = this_key.split('/')[-1] if this_key.startswith('/livetv/sessions') else None @@ -242,7 +241,6 @@ class ActivityHandler(object): last_state = db_session['state'] last_rating_key = str(db_session['rating_key']) last_live_uuid = db_session['live_uuid'] - last_view_offset = db_session['view_offset'] # Make sure the same item is being played if this_rating_key == last_rating_key or this_live_uuid == last_live_uuid: @@ -253,10 +251,6 @@ class ActivityHandler(object): if int(time.time()) - db_session['stopped'] > 60: self.update_db_session() - # Update db session when view offset changes - if this_view_offset != last_view_offset: - self.update_db_session() - # Start our state checks if this_state != last_state: if this_state == 'paused':