diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 8b0f6521..749983c4 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -540,6 +540,7 @@ def dbcheck(): 'transcode_hw_decoding INTEGER, transcode_hw_encoding INTEGER, ' 'optimized_version INTEGER, optimized_version_profile TEXT, optimized_version_title 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, ' 'write_attempts INTEGER DEFAULT 0, raw_stream_info TEXT)' ) @@ -1064,6 +1065,18 @@ def dbcheck(): '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 try: c_db.execute('SELECT reference_id FROM session_history') diff --git a/plexpy/activity_handler.py b/plexpy/activity_handler.py index d04cb4f2..34bd49ac 100644 --- a/plexpy/activity_handler.py +++ b/plexpy/activity_handler.py @@ -228,6 +228,11 @@ class ActivityHandler(object): this_state = self.timeline['state'] 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 db_session: # Re-schedule the callback to reset the 5 minutes timer @@ -236,9 +241,10 @@ class ActivityHandler(object): last_state = db_session['state'] last_key = str(db_session['rating_key']) + last_live_uuid = db_session['live_uuid'] # 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 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 d68311c1..4ce5c48f 100644 --- a/plexpy/activity_processor.py +++ b/plexpy/activity_processor.py @@ -114,7 +114,9 @@ class ActivityProcessor(object): 'stream_audio_channels': session.get('stream_audio_channels', ''), 'stream_subtitle_decision': session.get('stream_subtitle_decision', ''), '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), 'stopped': int(time.time()) } diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 6e7140a4..db5d9e0d 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -1659,6 +1659,7 @@ class PmsConnect(object): 'optimized_version_title': helpers.get_xml_attr(stream_media_info, 'title'), 'synced_version': 1 if sync_id else 0, 'live': int(helpers.get_xml_attr(session, 'live') == '1'), + 'live_uuid': helpers.get_xml_attr(stream_media_info, 'uuid'), 'indexes': int(indexes == 'sd'), 'bif_thumb': bif_thumb, 'subtitles': 1 if subtitle_id and subtitle_selected else 0