Stop Live TV session when guid changes

This commit is contained in:
JonnyWong16 2020-02-20 18:58:36 -08:00
parent 7b58bcc279
commit 751b97a39c
4 changed files with 30 additions and 7 deletions

View file

@ -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

View file

@ -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:

View file

@ -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),

View file

@ -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: