From ad682f3d1ba998d847ee97e2f8c59f35cb2983a9 Mon Sep 17 00:00:00 2001 From: Landon Abney Date: Mon, 18 Jun 2018 12:37:12 -0700 Subject: [PATCH] Fix time limit on paused stream monitoring The only way that this could ever be hit is if the stream is still active on the server, but the state is NOT one of paused, playing, or buffering. In case Plex decides to change the states in the future having this working properly is a good idea ;) --- killstream/kill_stream.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/killstream/kill_stream.py b/killstream/kill_stream.py index 15674fc..96d64f8 100644 --- a/killstream/kill_stream.py +++ b/killstream/kill_stream.py @@ -242,11 +242,12 @@ def terminate_long_pause(session_id, message, limit, interval, notify=None): stream. """ start = datetime.now() - fudge_factor = 100 # Keep checking this long after the defined limit - paused_time = 0 - check_limit = limit + interval + fudge_factor + checked_time = 0 + # Continue checking 2 intervals past the allowed limit in order to + # account for system variances. + check_limit = limit + (interval * 2) - while paused_time < check_limit: + while checked_time < check_limit: sessions = get_activity() found_session = False @@ -254,12 +255,11 @@ def terminate_long_pause(session_id, message, limit, interval, notify=None): if session['session_id'] == session_id: found_session = True state = session['state'] + now = datetime.now() + checked_time = (now - start).total_seconds() if state == 'paused': - now = datetime.now() - diff = now - start - - if diff.total_seconds() >= limit: + if checked_time >= limit: terminate_session(session_id, message, notify) sys.exit(0) else: