#155, adding kill when duration exceeds limit. Kill at limit.

This commit is contained in:
Blacktwin 2019-04-30 10:11:12 -04:00
parent f626a9daa1
commit 7db5c68061

View File

@ -50,6 +50,7 @@ import sys
import os import os
from plexapi.server import PlexServer, CONFIG from plexapi.server import PlexServer, CONFIG
from time import time as ttime from time import time as ttime
from time import sleep
TAUTULLI_URL = '' TAUTULLI_URL = ''
TAUTULLI_APIKEY = '' TAUTULLI_APIKEY = ''
@ -127,7 +128,7 @@ def send_notification(subject_text, body_text, notifier_id):
return None return None
def get_activity(): def get_activity(session_id=None):
"""Get the current activity on the PMS. """Get the current activity on the PMS.
Returns Returns
@ -137,12 +138,17 @@ def get_activity():
""" """
payload = {'apikey': TAUTULLI_APIKEY, payload = {'apikey': TAUTULLI_APIKEY,
'cmd': 'get_activity'} 'cmd': 'get_activity'}
if session_id:
payload['session_id'] = session_id
try: try:
req = sess.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload) req = sess.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload)
response = req.json() 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 return res_data
except Exception as e: except Exception as e:
@ -332,6 +338,16 @@ if __name__ == "__main__":
.format(opts.jbop, total_jbop, total_limit)) .format(opts.jbop, total_jbop, total_limit))
terminate_session(opts.sessionId, message, opts.notify, opts.username) terminate_session(opts.sessionId, message, opts.notify, opts.username)
elif (opts.duration + total_jbop) > total_limit: 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 ({}).' print('Total {} ({} + current item duration {}) is greater than limit ({}).'
.format(opts.jbop, total_jbop, opts.duration, total_limit)) .format(opts.jbop, total_jbop, opts.duration, total_limit))
terminate_session(opts.sessionId, message, opts.notify, opts.username) terminate_session(opts.sessionId, message, opts.notify, opts.username)