From 7db5c68061846bbf7208e4acc03c3c275706fdca Mon Sep 17 00:00:00 2001 From: Blacktwin Date: Tue, 30 Apr 2019 10:11:12 -0400 Subject: [PATCH] #155, adding kill when duration exceeds limit. Kill at limit. --- killstream/limiterr.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/killstream/limiterr.py b/killstream/limiterr.py index 99bb193..254e748 100644 --- a/killstream/limiterr.py +++ b/killstream/limiterr.py @@ -50,6 +50,7 @@ import sys import os from plexapi.server import PlexServer, CONFIG from time import time as ttime +from time import sleep TAUTULLI_URL = '' TAUTULLI_APIKEY = '' @@ -127,7 +128,7 @@ def send_notification(subject_text, body_text, notifier_id): return None -def get_activity(): +def get_activity(session_id=None): """Get the current activity on the PMS. Returns @@ -137,12 +138,17 @@ def get_activity(): """ payload = {'apikey': TAUTULLI_APIKEY, 'cmd': 'get_activity'} + if session_id: + payload['session_id'] = session_id try: req = sess.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload) response = req.json() - - res_data = response['response']['data']['sessions'] + + if session_id: + res_data = response['response']['data'] + else: + res_data = response['response']['data']['sessions'] return res_data except Exception as e: @@ -332,6 +338,16 @@ if __name__ == "__main__": .format(opts.jbop, total_jbop, total_limit)) terminate_session(opts.sessionId, message, opts.notify, opts.username) elif (opts.duration + total_jbop) > total_limit: + interval = 60 + start = 0 + while (start + total_jbop) < total_limit: + if get_activity(opts.sessionId): + sleep(interval) + start += interval + else: + print('Session; {} has been dropped. Stopping monitoring of stream.'.format(opts.sessionId)) + exit() + print('Total {} ({} + current item duration {}) is greater than limit ({}).' .format(opts.jbop, total_jbop, opts.duration, total_limit)) terminate_session(opts.sessionId, message, opts.notify, opts.username)