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 ;)
This commit is contained in:
Landon Abney 2018-06-18 12:37:12 -07:00
parent 4f3e35ef97
commit ad682f3d1b
No known key found for this signature in database
GPG Key ID: 4414384AEEE3FB2B

View File

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