2017-12-13 17:51:25 +00:00
|
|
|
"""
|
|
|
|
Kill Plex transcoding streams from specific libraries
|
|
|
|
|
2018-03-19 16:33:44 +00:00
|
|
|
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
2017-12-13 17:51:25 +00:00
|
|
|
[X] Notify on playback start
|
|
|
|
|
2018-03-19 16:33:44 +00:00
|
|
|
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
2017-12-13 17:51:25 +00:00
|
|
|
Playback Start: kill_trans_library.py
|
|
|
|
|
2018-03-19 16:33:44 +00:00
|
|
|
Tautulli > Settings > Notifications > Script > Script Arguments:
|
2018-01-24 18:45:13 +00:00
|
|
|
{section_id} {session_key}
|
2017-12-13 17:51:25 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
import requests
|
|
|
|
from plexapi.server import PlexServer
|
|
|
|
|
|
|
|
## EDIT THESE SETTINGS ##
|
|
|
|
PLEX_TOKEN = 'xxxxx'
|
|
|
|
PLEX_URL = 'http://localhost:32400'
|
|
|
|
|
|
|
|
TARGET_LIBRARIES = ['1', '2'] # Library IDs
|
|
|
|
|
|
|
|
DEFAULT_REASON = 'Stream terminated due to video transcoding of {} content. ' \
|
|
|
|
'Please set your device to use "Original" quality.'.format(', '.join(TARGET_LIBRARIES))
|
|
|
|
|
2018-03-19 16:33:44 +00:00
|
|
|
# Find platforms that have history in Tautulli in Play count by platform and stream type Graph
|
2017-12-13 17:51:25 +00:00
|
|
|
DEVICES = {'Android': 'Andriod message',
|
|
|
|
'Chrome': 'Chrome message',
|
|
|
|
'Plex Media Player': 'PMP message',
|
|
|
|
'Chromecast': 'Chromecast message'}
|
|
|
|
|
|
|
|
USER_IGNORE = ('') # ('Username','User2')
|
|
|
|
|
2018-03-19 16:33:44 +00:00
|
|
|
TAUTULLI_LOG = 'Killing {user}\'s stream of {title} due to video transcoding content from section {section}.'
|
2017-12-13 17:51:25 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
sess = requests.Session()
|
|
|
|
sess.verify = False
|
|
|
|
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
lib_id = sys.argv[1]
|
2018-02-14 13:34:10 +00:00
|
|
|
if lib_id not in TARGET_LIBRARIES:
|
|
|
|
print('Library accessed is allowed.')
|
|
|
|
exit()
|
2018-01-26 15:18:58 +00:00
|
|
|
session_key = int(sys.argv[2])
|
2017-12-13 17:51:25 +00:00
|
|
|
|
|
|
|
for session in plex.sessions():
|
|
|
|
username = session.usernames[0]
|
|
|
|
media_type = session.type
|
2018-01-24 18:45:13 +00:00
|
|
|
section_id = session.librarySectionID
|
2018-02-14 13:34:27 +00:00
|
|
|
if username not in USER_IGNORE and media_type != 'track' and session.sessionKey == session_key:
|
2017-12-13 17:51:25 +00:00
|
|
|
title = session.title
|
2018-01-26 15:18:58 +00:00
|
|
|
if session.transcodeSessions:
|
2018-01-24 18:45:13 +00:00
|
|
|
trans_dec = session.transcodeSessions[0].videoDecision
|
|
|
|
if trans_dec == 'transcode':
|
|
|
|
reason = DEVICES.get(session.players[0].platform, DEFAULT_REASON)
|
2018-03-19 16:33:44 +00:00
|
|
|
print(TAUTULLI_LOG.format(user=username, title=title, section=section_id))
|
2018-01-24 18:45:13 +00:00
|
|
|
session.stop(reason=reason)
|