From 5855fb3297618b92a5e10190219f04793d854328 Mon Sep 17 00:00:00 2001 From: blacktwin Date: Fri, 26 Jan 2018 09:16:03 -0500 Subject: [PATCH] session_key added session_key from session that caused the concurrent trigger will be collected. --- killstream/kill_more_than.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/killstream/kill_more_than.py b/killstream/kill_more_than.py index 10e410c..0035997 100644 --- a/killstream/kill_more_than.py +++ b/killstream/kill_more_than.py @@ -10,7 +10,7 @@ PlexPy > Settings > Notification Agents > Scripts > Gear icon: Playback User Concurrent Streams: kill_more_than.py PlexPy > Settings > Notifications > Script > Script Arguments - {username} {ip_address} + {username} {ip_address} {session_key} """ import requests @@ -28,6 +28,7 @@ ignore_lst = ('') # 2nd stream information is passed USERNAME = sys.argv[1] ADDRESS = sys.argv[2] +SESSION_KEY = sys.argv[3] if USERNAME in ignore_lst: print(u"{} ignored.".format(USERNAME)) @@ -38,7 +39,7 @@ sess.verify = False plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess) -def kill_session(user, ip_address): +def kill_session(user, ip_address, session_key): user_sessions = [] for session in plex.sessions(): @@ -49,14 +50,14 @@ def kill_session(user, ip_address): if len(user_sessions) == 1: for session in user_sessions: - username = session.usernames[0] - title = (session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title - print(u"Killing {}'s second stream of {} for {}".format(username, title, MESSAGE)) - session.stop(reason=MESSAGE) + if session_key == session.sessionKey: + title = (session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title + print(u"Killing {}'s second stream of {} for {}".format(username, title, MESSAGE)) + session.stop(reason=MESSAGE) else: for session in user_sessions: username = session.usernames[0] print(u"Not killing {}'s second stream. Same IP".format(username)) -kill_session(USERNAME, ADDRESS) +kill_session(USERNAME, ADDRESS, SESSION_KEY)