2017-07-12 18:23:52 +00:00
|
|
|
"""
|
|
|
|
Kill Plex paused video transcoding streams.
|
|
|
|
|
|
|
|
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
|
2017-10-05 17:40:33 +00:00
|
|
|
[X] Notify on playback start
|
2017-07-12 18:23:52 +00:00
|
|
|
|
|
|
|
PlexPy > Settings > Notification Agents > Scripts > Gear icon:
|
2017-10-05 17:41:41 +00:00
|
|
|
Playback Start: kill_trans_pause.py
|
2017-10-21 12:28:18 +00:00
|
|
|
|
|
|
|
PlexPy > Settings > Notifications > Script > Script Arguments:
|
|
|
|
{session_key}
|
|
|
|
|
2017-07-12 18:23:52 +00:00
|
|
|
"""
|
2017-10-21 12:28:18 +00:00
|
|
|
|
2017-07-12 18:23:52 +00:00
|
|
|
import requests
|
2017-10-05 17:40:33 +00:00
|
|
|
import sys
|
2017-10-21 12:28:18 +00:00
|
|
|
from plexapi.server import PlexServer
|
2017-07-12 18:23:52 +00:00
|
|
|
|
|
|
|
## EDIT THESE SETTINGS ##
|
2017-10-21 12:28:18 +00:00
|
|
|
PLEX_TOKEN = 'xxxx'
|
|
|
|
PLEX_URL = 'http://localhost:32400'
|
2017-07-12 18:23:52 +00:00
|
|
|
|
2017-10-21 12:28:18 +00:00
|
|
|
MESSAGE = "You are not allowed to stream above 4 Mbps."
|
2017-07-12 18:23:52 +00:00
|
|
|
|
2017-10-21 12:28:18 +00:00
|
|
|
ignore_lst = ('')
|
|
|
|
##/EDIT THESE SETTINGS ##
|
2017-07-12 18:23:52 +00:00
|
|
|
|
2017-10-21 12:28:18 +00:00
|
|
|
sess = requests.Session()
|
|
|
|
sess.verify = False
|
|
|
|
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
2017-07-12 18:23:52 +00:00
|
|
|
|
2017-10-21 12:28:18 +00:00
|
|
|
def kill_session(sess_key):
|
|
|
|
for session in plex.sessions():
|
|
|
|
user = session.username[0]
|
|
|
|
if user in ignore_lst:
|
2017-10-21 12:52:46 +00:00
|
|
|
print('Ignoring {}\'s paused transcode stream.'.format(user))
|
2017-10-21 12:28:18 +00:00
|
|
|
exit()
|
|
|
|
state = session.players[0].state
|
2017-12-13 04:13:04 +00:00
|
|
|
trans_dec = session.transcodeSessions[0].videoDecision
|
2017-10-21 12:28:18 +00:00
|
|
|
if session.sessionKey is sess_key and state == 'paused' and trans_dec == 'transcode':
|
|
|
|
title = (session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title
|
|
|
|
print('Killing {user}\'s stream for pausing a transcode stream of {title}.'.format(user=user, title=title))
|
|
|
|
session.stop(reason=MESSAGE)
|
2017-10-05 17:40:33 +00:00
|
|
|
|
2017-07-12 18:23:52 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-10-21 12:28:18 +00:00
|
|
|
session_key = sys.argv[1]
|
|
|
|
kill_session(session_key)
|