diff --git a/plexpy/activity_pinger.py b/plexpy/activity_pinger.py index c07ea77b..98127b7f 100644 --- a/plexpy/activity_pinger.py +++ b/plexpy/activity_pinger.py @@ -173,11 +173,12 @@ def check_active_sessions(ws_request=False): if stream['state'] != 'stopped': logger.debug(u"PlexPy Monitor :: Session %s has stopped." % stream['session_key']) - # Set the stream stop time - stream['stopped'] = int(time.time()) - monitor_db.action('UPDATE sessions SET stopped = ?, state = ? ' - 'WHERE session_key = ? AND rating_key = ?', - [stream['stopped'], 'stopped', stream['session_key'], stream['rating_key']]) + if not stream['stopped']: + # Set the stream stop time + stream['stopped'] = int(time.time()) + monitor_db.action('UPDATE sessions SET stopped = ?, state = ? ' + 'WHERE session_key = ? AND rating_key = ?', + [stream['stopped'], 'stopped', stream['session_key'], stream['rating_key']]) # Check if the user has reached the offset in the media we defined as the "watched" percent if stream['view_offset'] and stream['duration']: @@ -236,6 +237,11 @@ def check_active_sessions(ws_request=False): else: logger.debug(u"PlexPy Monitor :: Unable to read session list.") + if int_ping_count == 0: + # Temporarily set the stopped time for all sessions + stopped_time = int(time.time()) + monitor_db.action('UPDATE sessions SET stopped = ?', [stopped_time]) + int_ping_count += 1 logger.warn(u"PlexPy Monitor :: Unable to get an internal response from the server, ping attempt %s." \ % str(int_ping_count)) diff --git a/plexpy/activity_processor.py b/plexpy/activity_processor.py index 9e731514..0842ad9f 100644 --- a/plexpy/activity_processor.py +++ b/plexpy/activity_processor.py @@ -82,7 +82,8 @@ class ActivityProcessor(object): 'transcode_audio_codec': session['transcode_audio_codec'], 'transcode_audio_channels': session['transcode_audio_channels'], 'transcode_width': session['transcode_width'], - 'transcode_height': session['transcode_height'] + 'transcode_height': session['transcode_height'], + 'stopped': None } # Add ip_address back into values