Improved checking of live tv session websocket events

This commit is contained in:
JonnyWong16 2018-05-26 10:14:36 -07:00
parent 2366a8811b
commit aa365eb6a3
4 changed files with 24 additions and 2 deletions

View file

@ -540,6 +540,7 @@ def dbcheck():
'transcode_hw_decoding INTEGER, transcode_hw_encoding INTEGER, ' 'transcode_hw_decoding INTEGER, transcode_hw_encoding INTEGER, '
'optimized_version INTEGER, optimized_version_profile TEXT, optimized_version_title TEXT, ' 'optimized_version INTEGER, optimized_version_profile TEXT, optimized_version_title TEXT, '
'synced_version INTEGER, synced_version_profile TEXT, ' 'synced_version INTEGER, synced_version_profile TEXT, '
'live INTEGER, live_uuid TEXT, '
'buffer_count INTEGER DEFAULT 0, buffer_last_triggered INTEGER, last_paused INTEGER, watched INTEGER DEFAULT 0, ' 'buffer_count INTEGER DEFAULT 0, buffer_last_triggered INTEGER, last_paused INTEGER, watched INTEGER DEFAULT 0, '
'write_attempts INTEGER DEFAULT 0, raw_stream_info TEXT)' 'write_attempts INTEGER DEFAULT 0, raw_stream_info TEXT)'
) )
@ -1064,6 +1065,18 @@ def dbcheck():
'ALTER TABLE sessions ADD COLUMN watched INTEGER DEFAULT 0' 'ALTER TABLE sessions ADD COLUMN watched INTEGER DEFAULT 0'
) )
# Upgrade sessions table from earlier versions
try:
c_db.execute('SELECT live FROM sessions')
except sqlite3.OperationalError:
logger.debug(u"Altering database. Updating database table sessions.")
c_db.execute(
'ALTER TABLE sessions ADD COLUMN live INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN live_uuid TEXT'
)
# Upgrade session_history table from earlier versions # Upgrade session_history table from earlier versions
try: try:
c_db.execute('SELECT reference_id FROM session_history') c_db.execute('SELECT reference_id FROM session_history')

View file

@ -228,6 +228,11 @@ class ActivityHandler(object):
this_state = self.timeline['state'] this_state = self.timeline['state']
this_key = str(self.timeline['ratingKey']) this_key = str(self.timeline['ratingKey'])
# Get the live tv session uuid
this_live_uuid = None
if this_key.startswith('tv.plex.xmltv://'):
this_live_uuid = self.timeline['key'].split('/')[-1]
# If we already have this session in the temp table, check for state changes # If we already have this session in the temp table, check for state changes
if db_session: if db_session:
# Re-schedule the callback to reset the 5 minutes timer # Re-schedule the callback to reset the 5 minutes timer
@ -236,9 +241,10 @@ class ActivityHandler(object):
last_state = db_session['state'] last_state = db_session['state']
last_key = str(db_session['rating_key']) last_key = str(db_session['rating_key'])
last_live_uuid = db_session['live_uuid']
# Make sure the same item is being played # Make sure the same item is being played
if this_key == last_key: if this_key == last_key or this_live_uuid == last_live_uuid:
# Update the session state and viewOffset # Update the session state and viewOffset
if this_state == 'playing': if this_state == 'playing':
# Update the session in our temp session table # Update the session in our temp session table

View file

@ -114,7 +114,9 @@ class ActivityProcessor(object):
'stream_audio_channels': session.get('stream_audio_channels', ''), 'stream_audio_channels': session.get('stream_audio_channels', ''),
'stream_subtitle_decision': session.get('stream_subtitle_decision', ''), 'stream_subtitle_decision': session.get('stream_subtitle_decision', ''),
'stream_subtitle_codec': session.get('stream_subtitle_codec', ''), 'stream_subtitle_codec': session.get('stream_subtitle_codec', ''),
'subtitles': session.get('subtitles', ''), 'subtitles': session.get('subtitles', 0),
'live': session.get('live', 0),
'live_uuid': session.get('live_uuid', ''),
'raw_stream_info': json.dumps(session), 'raw_stream_info': json.dumps(session),
'stopped': int(time.time()) 'stopped': int(time.time())
} }

View file

@ -1659,6 +1659,7 @@ class PmsConnect(object):
'optimized_version_title': helpers.get_xml_attr(stream_media_info, 'title'), 'optimized_version_title': helpers.get_xml_attr(stream_media_info, 'title'),
'synced_version': 1 if sync_id else 0, 'synced_version': 1 if sync_id else 0,
'live': int(helpers.get_xml_attr(session, 'live') == '1'), 'live': int(helpers.get_xml_attr(session, 'live') == '1'),
'live_uuid': helpers.get_xml_attr(stream_media_info, 'uuid'),
'indexes': int(indexes == 'sd'), 'indexes': int(indexes == 'sd'),
'bif_thumb': bif_thumb, 'bif_thumb': bif_thumb,
'subtitles': 1 if subtitle_id and subtitle_selected else 0 'subtitles': 1 if subtitle_id and subtitle_selected else 0