JBOPS/killstream/kill_trans_pause.py

49 lines
1.4 KiB
Python
Raw Normal View History

"""
Kill Plex paused video transcoding streams.
PlexPy > Settings > Notification Agents > Scripts > Bell icon:
[X] Notify on playback start
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-10-21 12:28:18 +00:00
import requests
import sys
2017-10-21 12:28:18 +00:00
from plexapi.server import PlexServer
## EDIT THESE SETTINGS ##
2017-10-21 12:28:18 +00:00
PLEX_TOKEN = 'xxxx'
PLEX_URL = 'http://localhost:32400'
2017-10-21 12:28:18 +00:00
MESSAGE = "You are not allowed to stream above 4 Mbps."
2017-10-21 12:28:18 +00:00
ignore_lst = ('')
##/EDIT THESE SETTINGS ##
2017-10-21 12:28:18 +00:00
sess = requests.Session()
sess.verify = False
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
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
trans_dec = session.trancodeSessions[0].videoDecision
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)
if __name__ == '__main__':
2017-10-21 12:28:18 +00:00
session_key = sys.argv[1]
kill_session(session_key)