forked from blacktwin/JBOPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kill_all_more_than.py
48 lines (35 loc) · 1.3 KB
/
kill_all_more_than.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
If user has 2* or more concurrent streams kill all user's streams
*Tautulli > Settings > Notification> User Concurrent Stream Threshold
The number of concurrent streams by a single user for Tautulli to trigger a notification. Minimum 2.
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
[X] Notify on user concurrent streams
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
Playback User Concurrent Streams: kill_more_than.py
Tautulli > Settings > Notifications > Script > Script Arguments
{user}
"""
import requests
import sys
from plexapi.server import PlexServer
## EDIT THESE SETTINGS ##
PLEX_TOKEN = 'xxxxx'
PLEX_URL = 'http://localhost:32400'
MESSAGE = 'Because....too many streams'
ignore_lst = ('')
## EDIT THESE SETTINGS ##
# 2nd stream information is passed
USERNAME = sys.argv[1]
if USERNAME in ignore_lst:
print(u"{} ignored.".format(USERNAME))
exit()
sess = requests.Session()
sess.verify = False
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
def kill_session(user):
for session in plex.sessions():
# Check for users stream
if session.usernames[0] in user:
print('Killing all of {user}\'s streams. Too many streams'.format(user=user))
session.stop(reason=MESSAGE)
kill_session(USERNAME)