JBOPS/killstream/kill_plex_streams.py

42 lines
1.0 KiB
Python
Raw Normal View History

2017-10-20 18:55:38 +00:00
"""
Kill all Plex sessions
2017-10-20 18:55:38 +00:00
"""
import sys
2017-10-20 18:55:38 +00:00
import requests
from plexapi.server import PlexServer
import configparser
2017-10-20 18:55:38 +00:00
# EDIT THESE SETTINGS #
PLEX_URL = '' # leave blank if using config.ini. Overrides config
PLEX_TOKEN = '' # leave blank if using config.ini. Overrides config
2017-10-20 18:55:38 +00:00
MESSAGE = 'Because....'
# /EDIT THESE SETTINGS #
config = configparser.ConfigParser()
try:
config.read('../config.ini')
if not PLEX_URL:
PLEX_URL = config.get('plex', 'url')
if not PLEX_TOKEN:
PLEX_TOKEN = config.get('plex', 'token')
except configparser.NoSectionError:
sys.exit('Error: No config and missing var values.')
2017-10-20 18:55:38 +00:00
sess = requests.Session()
sess.verify = False
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
def kill_sessions():
2017-10-20 18:55:38 +00:00
for session in plex.sessions():
2017-10-21 18:59:23 +00:00
user = session.usernames[0]
title = (session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title
print("Killing {}'s stream of {} for {}".format(user, title, MESSAGE))
session.stop(reason=MESSAGE)
2017-10-20 18:55:38 +00:00
kill_sessions()