diff --git a/plexpy/activity_handler.py b/plexpy/activity_handler.py index b65ebff6..f16f6ead 100644 --- a/plexpy/activity_handler.py +++ b/plexpy/activity_handler.py @@ -58,6 +58,16 @@ class ActivityHandler(object): return None + def get_metadata(self, skip_cache=False): + cache_key = None if skip_cache else self.get_session_key() + pms_connect = pmsconnect.PmsConnect() + metadata = pms_connect.get_metadata_details(rating_key=self.get_rating_key(), cache_key=cache_key) + + if metadata: + return metadata + + return None + def get_live_session(self): pms_connect = pmsconnect.PmsConnect() session_list = pms_connect.get_current_activity() @@ -269,11 +279,19 @@ class ActivityHandler(object): last_transcode_key = db_session['transcode_key'].split('/')[-1] last_paused = db_session['last_paused'] last_rating_key_websocket = db_session['rating_key_websocket'] + last_guid = db_session['guid'] + + this_guid = last_guid + if db_session['live']: + metadata = self.get_metadata() + if metadata: + this_guid = metadata['guid'] # Make sure the same item is being played - if this_rating_key == last_rating_key \ - or this_rating_key == last_rating_key_websocket \ - or this_live_uuid == last_live_uuid: + if (this_rating_key == last_rating_key + or this_rating_key == last_rating_key_websocket + or this_live_uuid == last_live_uuid) \ + and this_guid == last_guid: # Update the session state and viewOffset if this_state == 'playing': # Update the session in our temp session table diff --git a/plexpy/activity_processor.py b/plexpy/activity_processor.py index ee161aab..deeb5436 100644 --- a/plexpy/activity_processor.py +++ b/plexpy/activity_processor.py @@ -247,7 +247,7 @@ class ActivityProcessor(object): if session['live']: metadata = pms_connect.get_metadata_details(rating_key=str(session['rating_key']), cache_key=session['session_key'], - skip_cache_time=True) + return_cache=True) else: metadata = pms_connect.get_metadata_details(rating_key=str(session['rating_key'])) if not metadata: diff --git a/plexpy/config.py b/plexpy/config.py index 82159e0d..98adac10 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -294,6 +294,7 @@ _CONFIG_DEFINITIONS = { 'LOGGING_LIVE_TV': (int, 'Monitoring', 1), 'MAXMIND_LICENSE_KEY': (str, 'General', ''), 'METADATA_CACHE_SECONDS': (int, 'Advanced', 1800), + 'METADATA_LIVE_CACHE_SECONDS': (int, 'Advanced', 60), 'MOVIE_LOGGING_ENABLE': (int, 'Monitoring', 1), 'MOVIE_NOTIFY_ENABLE': (int, 'Monitoring', 0), 'MOVIE_NOTIFY_ON_START': (int, 'Monitoring', 1), diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index a67412fd..ea8839b4 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -572,7 +572,7 @@ class PmsConnect(object): return output def get_metadata_details(self, rating_key='', sync_id='', plex_guid='', - cache_key=None, skip_cache_time=False, media_info=True): + cache_key=None, return_cache=False, media_info=True): """ Return processed and validated metadata list for requested item. @@ -597,8 +597,12 @@ class PmsConnect(object): if metadata: _cache_time = metadata.pop('_cache_time', 0) - # Return cached metadata if less than METADATA_CACHE_SECONDS ago - if skip_cache_time or int(time.time()) - _cache_time <= plexpy.CONFIG.METADATA_CACHE_SECONDS: + if metadata['live']: + cache_seconds = plexpy.CONFIG.METADATA_LIVE_CACHE_SECONDS + else: + cache_seconds = plexpy.CONFIG.METADATA_CACHE_SECONDS + # Return cached metadata if less than cache_seconds ago + if return_cache or int(time.time()) - _cache_time <= cache_seconds: return metadata if rating_key: