cleanup. removing kill scripts that can now be done through conditions
This commit is contained in:
@ -1,91 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
'''
|
|
||||||
Receive session_key and IP from Tautulli when playback starts.
|
|
||||||
Use IP to check against whitelist.
|
|
||||||
If not in whitelist use session_key to determine stream and kill.
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on playback start
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Start: ip_whitelist.py
|
|
||||||
Tautulli > Settings > Notifications > Script > Script Arguments:
|
|
||||||
{session_key} {ip_address}
|
|
||||||
|
|
||||||
'''
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import requests
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
import configparser
|
|
||||||
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
PLEX_TOKEN = 'xxxxxx'
|
|
||||||
PLEX_URL = 'http://localhost:32400'
|
|
||||||
|
|
||||||
TAUTULLI_APIKEY = 'xxxxxx' # Your Tautulli API key
|
|
||||||
TAUTULLI_URL = 'http://localhost:8182/' # Your Tautulli URL
|
|
||||||
|
|
||||||
IP_WHITELIST = ['10.10.0.12'] # List IP addresses.
|
|
||||||
IGNORE_LST = ('') # List usernames that should be ignored.
|
|
||||||
|
|
||||||
REASON = 'IP Address: {} was not found in whitelist.'
|
|
||||||
|
|
||||||
NOTIFIER_ID = 14 # Notification agent ID for Tautulli
|
|
||||||
# Find Notification agent ID here:
|
|
||||||
# Tautulli Settings -> NOTIFICATION AGENTS -> :bell: Agent (NotifierID - {Description)
|
|
||||||
|
|
||||||
SUBJECT_TEXT = "IP Whitelist Violation"
|
|
||||||
BODY_TEXT = "Killed {user}'s stream of {title}. IP: {ip} not in whitelist"
|
|
||||||
##/EDIT THESE SETTINGS ##
|
|
||||||
|
|
||||||
sessionKey = sys.argv[1]
|
|
||||||
ip_address = sys.argv[2]
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
def send_notification(subject_text, body_text):
|
|
||||||
# Format notification text
|
|
||||||
try:
|
|
||||||
subject = subject_text
|
|
||||||
body = body_text
|
|
||||||
|
|
||||||
except LookupError as e:
|
|
||||||
sys.stderr.write("Unable to substitute '{0}' in the notification subject or body".format(e))
|
|
||||||
return None
|
|
||||||
# Send the notification through Tautulli
|
|
||||||
payload = {'apikey': TAUTULLI_APIKEY,
|
|
||||||
'cmd': 'notify',
|
|
||||||
'notifier_id': NOTIFIER_ID,
|
|
||||||
'subject': subject,
|
|
||||||
'body': body}
|
|
||||||
|
|
||||||
try:
|
|
||||||
r = requests.post(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload)
|
|
||||||
response = r.json()
|
|
||||||
|
|
||||||
if response['response']['result'] == 'success':
|
|
||||||
sys.stdout.write("Successfully sent Tautulli notification.")
|
|
||||||
else:
|
|
||||||
raise Exception(response['response']['message'])
|
|
||||||
except Exception as e:
|
|
||||||
sys.stderr.write("Tautulli API 'notify' request failed: {0}.".format(e))
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
if ip_address not in IP_WHITELIST:
|
|
||||||
for session in plex.sessions():
|
|
||||||
username = session.usernames[0]
|
|
||||||
title = (session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title
|
|
||||||
if session.sessionKey == int(sessionKey) and username not in IGNORE_LST:
|
|
||||||
sys.stdout.write("Killing {user}'s stream of {title}. IP: {ip} not in whitelist".format(
|
|
||||||
user=username, title=title, ip=ip_address))
|
|
||||||
session.stop(reason=REASON.format(ip_address))
|
|
||||||
send_notification(SUBJECT_TEXT, BODY_TEXT.format(user=username, ip=ip_address, title=title))
|
|
||||||
else:
|
|
||||||
sys.stdout.write('User: {} is ignored from this script.'.format(username))
|
|
||||||
else:
|
|
||||||
sys.stdout.write('IP: {} is in whitelist, ignoring.'.format(ip_address))
|
|
@ -1,51 +0,0 @@
|
|||||||
"""
|
|
||||||
Kill Plex streams based on device.
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on playback start
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Start: kill_device.py
|
|
||||||
|
|
||||||
"""
|
|
||||||
import requests
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
PLEX_TOKEN = 'xxxxxx'
|
|
||||||
PLEX_URL = 'http://localhost:32400'
|
|
||||||
|
|
||||||
DEFAULT_REASON = 'This stream has ended due to your device type.'
|
|
||||||
|
|
||||||
# Find platforms that have history in Tautulli in Play count by platform and stream type Graph
|
|
||||||
DEVICES = {'Android': 'Andriod message',
|
|
||||||
'Chrome': 'Chrome message',
|
|
||||||
'Plex Media Player': 'PMP message',
|
|
||||||
'Chromecast': 'Chromecast message'}
|
|
||||||
|
|
||||||
USER_IGNORE = ('') # ('Username','User2')
|
|
||||||
##/EDIT THESE SETTINGS ##
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
def kill_session():
|
|
||||||
|
|
||||||
for session in plex.sessions():
|
|
||||||
user = session.usernames[0]
|
|
||||||
if user in USER_IGNORE:
|
|
||||||
print('Ignoring {}\'s stream from platform check.'.format(user))
|
|
||||||
exit()
|
|
||||||
|
|
||||||
platform = session.players[0].platform
|
|
||||||
if DEVICES.get(platform):
|
|
||||||
MESSAGE = DEVICES.get(platform, DEFAULT_REASON)
|
|
||||||
print('Killing {user}\'s stream on {plat}.'.format(user=user, plat=platform))
|
|
||||||
session.stop(reason=MESSAGE)
|
|
||||||
else:
|
|
||||||
print('{user}\'s stream on {plat} is allowed to play.'.format(user=user, plat=platform))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
kill_session()
|
|
@ -1,44 +0,0 @@
|
|||||||
"""
|
|
||||||
Kill stream of user if they are accessing Plex from outside network
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on playback start
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Start: kill_outsider_stream.py
|
|
||||||
|
|
||||||
Tautulli > Settings > Notifications > Script > Script Arguments
|
|
||||||
{username}
|
|
||||||
"""
|
|
||||||
|
|
||||||
import requests
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
import sys
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
PLEX_TOKEN = 'xxxxx'
|
|
||||||
PLEX_URL = 'http://localhost:32400'
|
|
||||||
MESSAGE = 'Accessing Plex from outside network'
|
|
||||||
|
|
||||||
ignore_lst = ('')
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
|
|
||||||
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] == user and session.players[0].local is False:
|
|
||||||
title = (session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title
|
|
||||||
print('{user} is watching {title} and they might be asleep.'.format(user=user, title=title))
|
|
||||||
session.stop(reason=MESSAGE)
|
|
||||||
|
|
||||||
kill_session(USERNAME)
|
|
@ -1,41 +0,0 @@
|
|||||||
"""
|
|
||||||
Kill all Plex sessions
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import requests
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
import configparser
|
|
||||||
|
|
||||||
# EDIT THESE SETTINGS #
|
|
||||||
PLEX_URL = '' # leave blank if using config.ini. Overrides config
|
|
||||||
PLEX_TOKEN = '' # leave blank if using config.ini. Overrides config
|
|
||||||
|
|
||||||
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.')
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
|
|
||||||
def kill_sessions():
|
|
||||||
for session in plex.sessions():
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
kill_sessions()
|
|
@ -1,37 +0,0 @@
|
|||||||
"""
|
|
||||||
Kill stream if bitrate is > BITRATE_LIMIT
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on playback start
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Start: kill_session_bitrate.py
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
import requests
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
PLEX_TOKEN = 'xxxxx'
|
|
||||||
PLEX_URL = 'http://localhost:32400'
|
|
||||||
|
|
||||||
MESSAGE = "You are not allowed to stream above 4 Mbps."
|
|
||||||
|
|
||||||
ignore_lst = ('')
|
|
||||||
##/EDIT THESE SETTINGS ##
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
def kill_session():
|
|
||||||
for session in plex.sessions():
|
|
||||||
bitrate = session.media[0].parts[0].streams[0].bitrate
|
|
||||||
user = session.usernames[0]
|
|
||||||
if user not in ignore_lst and int(bitrate) > 4000:
|
|
||||||
title = (session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title
|
|
||||||
print('{user} is watching {title} and they might be asleep.'.format(user=user, title=title))
|
|
||||||
session.stop(reason=MESSAGE)
|
|
||||||
|
|
||||||
kill_session()
|
|
@ -1,58 +0,0 @@
|
|||||||
"""
|
|
||||||
Kill Plex video transcoding streams only. All audio streams are left alone.
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on playback start
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Start: kill_trans_exp_audio.py
|
|
||||||
|
|
||||||
"""
|
|
||||||
import requests
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
PLEX_TOKEN = 'xxxx'
|
|
||||||
PLEX_URL = 'http://localhost:32400'
|
|
||||||
|
|
||||||
DEFAULT_REASON = 'This stream has ended due to requiring video transcoding. ' \
|
|
||||||
'Please raise your Remote Quality to Original to play this content.'
|
|
||||||
|
|
||||||
# Find platforms that have history in Tautulli in Play count by platform and stream type Graph
|
|
||||||
DEVICES = {'Android': 'Andriod message',
|
|
||||||
'Chrome': 'Chrome message',
|
|
||||||
'Plex Media Player': 'PMP message',
|
|
||||||
'Chromecast': 'Chromecast message'}
|
|
||||||
|
|
||||||
USER_IGNORE = ('') # ('Username','User2')
|
|
||||||
##/EDIT THESE SETTINGS ##
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
|
|
||||||
def kill_session():
|
|
||||||
for session in plex.sessions():
|
|
||||||
user = session.usernames[0]
|
|
||||||
media_type = session.type
|
|
||||||
if user in USER_IGNORE or media_type == 'track':
|
|
||||||
print('Ignoring {}\'s {} stream.'.format(user, media_type))
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
trans_dec = session.transcodeSessions[0].videoDecision
|
|
||||||
if trans_dec == 'transcode':
|
|
||||||
platform = session.players[0].platform
|
|
||||||
MESSAGE = DEVICES.get(platform, DEFAULT_REASON)
|
|
||||||
# print(MESSAGE)
|
|
||||||
print('Killing {user}\'s stream for transcoding video on {plat}.'.format(user=user, plat=platform))
|
|
||||||
session.stop(reason=MESSAGE)
|
|
||||||
except IndexError:
|
|
||||||
# print('{} not transcoding.'.format(user))
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
kill_session()
|
|
@ -1,61 +0,0 @@
|
|||||||
"""
|
|
||||||
Kill Plex transcoding streams from specific libraries
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on playback start
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Start: kill_trans_library.py
|
|
||||||
|
|
||||||
Tautulli > Settings > Notifications > Script > Script Arguments:
|
|
||||||
{section_id} {session_key}
|
|
||||||
|
|
||||||
"""
|
|
||||||
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))
|
|
||||||
|
|
||||||
# Find platforms that have history in Tautulli in Play count by platform and stream type Graph
|
|
||||||
DEVICES = {'Android': 'Andriod message',
|
|
||||||
'Chrome': 'Chrome message',
|
|
||||||
'Plex Media Player': 'PMP message',
|
|
||||||
'Chromecast': 'Chromecast message'}
|
|
||||||
|
|
||||||
USER_IGNORE = ('') # ('Username','User2')
|
|
||||||
|
|
||||||
TAUTULLI_LOG = 'Killing {user}\'s stream of {title} due to video transcoding content from section {section}.'
|
|
||||||
##
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
lib_id = sys.argv[1]
|
|
||||||
if lib_id not in TARGET_LIBRARIES:
|
|
||||||
print('Library accessed is allowed.')
|
|
||||||
exit()
|
|
||||||
session_key = int(sys.argv[2])
|
|
||||||
|
|
||||||
for session in plex.sessions():
|
|
||||||
username = session.usernames[0]
|
|
||||||
media_type = session.type
|
|
||||||
section_id = session.librarySectionID
|
|
||||||
if username not in USER_IGNORE and media_type != 'track' and session.sessionKey == session_key:
|
|
||||||
title = session.title
|
|
||||||
if session.transcodeSessions:
|
|
||||||
trans_dec = session.transcodeSessions[0].videoDecision
|
|
||||||
if trans_dec == 'transcode':
|
|
||||||
reason = DEVICES.get(session.players[0].platform, DEFAULT_REASON)
|
|
||||||
print(TAUTULLI_LOG.format(user=username, title=title, section=section_id))
|
|
||||||
session.stop(reason=reason)
|
|
@ -1,49 +0,0 @@
|
|||||||
"""
|
|
||||||
Kill Plex paused video transcoding streams.
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on playback pause
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Pause: kill_trans_pause.py
|
|
||||||
|
|
||||||
Tautulli > Settings > Notifications > Script > Script Arguments:
|
|
||||||
{session_key}
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
import requests
|
|
||||||
import sys
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
PLEX_TOKEN = 'xxxx'
|
|
||||||
PLEX_URL = 'http://localhost:32400'
|
|
||||||
|
|
||||||
MESSAGE = "You've paused a transcoded stream."
|
|
||||||
|
|
||||||
ignore_lst = ('')
|
|
||||||
##/EDIT THESE SETTINGS ##
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
def kill_session(sess_key):
|
|
||||||
for session in plex.sessions():
|
|
||||||
user = session.usernames[0]
|
|
||||||
if user in ignore_lst:
|
|
||||||
print('Ignoring {}\'s paused transcode stream.'.format(user))
|
|
||||||
exit()
|
|
||||||
state = session.players[0].state
|
|
||||||
if session.transcodeSessions:
|
|
||||||
trans_dec = session.transcodeSessions[0].videoDecision
|
|
||||||
if session.sessionKey == 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__':
|
|
||||||
session_key = int(sys.argv[1])
|
|
||||||
kill_session(session_key)
|
|
@ -1,58 +0,0 @@
|
|||||||
"""
|
|
||||||
Kill Plex transcoding streams only. Checks original quality.
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on playback start
|
|
||||||
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Start: kill_trans_quality.py
|
|
||||||
|
|
||||||
Tautulli > Settings > Notifications > Script > Script Arguments:
|
|
||||||
{rating_key}
|
|
||||||
|
|
||||||
"""
|
|
||||||
import sys
|
|
||||||
import requests
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
PLEX_TOKEN = 'xxxx'
|
|
||||||
PLEX_URL = 'http://localhost:32400'
|
|
||||||
|
|
||||||
TARGET_QUALITY = ['1080', '4k']
|
|
||||||
|
|
||||||
DEFAULT_REASON = 'Stream terminated due to video transcoding of {} content. ' \
|
|
||||||
'Please set your device to use "Original" quality.'.format(', '.join(TARGET_QUALITY))
|
|
||||||
|
|
||||||
DEVICES = {'Android': 'Andriod message',
|
|
||||||
'Chrome': 'Chrome message',
|
|
||||||
'Plex Media Player': 'PMP message',
|
|
||||||
'Chromecast': 'Chromecast message'}
|
|
||||||
|
|
||||||
USER_IGNORE = ('') # ('Username','User2')
|
|
||||||
|
|
||||||
TAUTULLI_LOG = 'Killing {user}\'s stream of {title} due to video transcoding of {original} content'
|
|
||||||
##
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
rating_key = sys.argv[1]
|
|
||||||
item = plex.fetchItem(int(rating_key))
|
|
||||||
orig_quality = item.media[0].videoResolution
|
|
||||||
# print(orig_quality)
|
|
||||||
|
|
||||||
for session in plex.sessions():
|
|
||||||
username = session.usernames[0]
|
|
||||||
media_type = session.type
|
|
||||||
if username not in USER_IGNORE and media_type != 'track':
|
|
||||||
title = session.title
|
|
||||||
sess_rating = session.key.split('/')[3]
|
|
||||||
trans_dec = session.transcodeSessions[0].videoDecision
|
|
||||||
if sess_rating == str(rating_key) and orig_quality in TARGET_QUALITY and trans_dec == 'transcode':
|
|
||||||
reason = DEVICES.get(session.players[0].platform, DEFAULT_REASON)
|
|
||||||
print(TAUTULLI_LOG.format(user=username, title=title,original=orig_quality))
|
|
||||||
session.stop(reason=reason)
|
|
@ -1,120 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
'''
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
|
|
||||||
[X] Notify on pause
|
|
||||||
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
|
|
||||||
Playback Pause: wait_kill_pause_notify_main.py
|
|
||||||
Tautulli > Settings > Notifications > Script > Script Arguments:
|
|
||||||
{session_key}
|
|
||||||
|
|
||||||
wait_kill_pause_notify_main.py & wait_kill_pause_notify_sub.py should be in the same directory.
|
|
||||||
wait_kill_pause_notify_main.py executes sub_script wait_kill_pause_notify_sub.py.
|
|
||||||
|
|
||||||
Tautulli will timeout wait_kill_pause_notify_main.py after 30 seconds (default)
|
|
||||||
but wait_kill_pause_notify_sub.py will continue.
|
|
||||||
|
|
||||||
wait_kill_pause_notify_sub will check if the stream's session_id is still paused or if playing as restarted.
|
|
||||||
If playback is restarted then wait_kill_pause_notify_sub will stop and delete itself.
|
|
||||||
If stream remains paused then it will be killed and wait_kill_pause_notify_sub will stop.
|
|
||||||
Set TIMEOUT to max time before killing stream
|
|
||||||
Set INTERVAL to how often you want to check the stream status
|
|
||||||
'''
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import requests
|
|
||||||
import subprocess
|
|
||||||
from plexapi.server import PlexServer
|
|
||||||
|
|
||||||
|
|
||||||
## EDIT THESE SETTINGS ##
|
|
||||||
PLEX_TOKEN = ''
|
|
||||||
PLEX_URL = 'http://localhost:32400'
|
|
||||||
TAUTULLI_APIKEY = '' # Your Tautulli API key
|
|
||||||
TAUTULLI_URL = 'http://localhost:8182/' # Your Tautulli URL
|
|
||||||
|
|
||||||
TIMEOUT = '120'
|
|
||||||
INTERVAL = '20'
|
|
||||||
|
|
||||||
KILL_MESSAGE = 'This stream has ended due to being paused.'
|
|
||||||
|
|
||||||
USER_IGNORE = ('') # ('Username','User2')
|
|
||||||
|
|
||||||
SUBJECT_TEXT = "Killed Paused Transcoded Stream."
|
|
||||||
BODY_TEXT = "Killed {user}'s paused transcoded stream of {title}."
|
|
||||||
|
|
||||||
NOTIFIER_ID = 10 # Notification agent ID for Tautulli
|
|
||||||
# Find Notification agent ID here:
|
|
||||||
# Tautulli Settings -> NOTIFICATION AGENTS -> :bell: Agent (NotifierID - {Description)
|
|
||||||
# NOTIFIER_ID = '' to disable notification
|
|
||||||
|
|
||||||
sub_script = 'wait_kill_pause_notify_sub.py'
|
|
||||||
##/EDIT THESE SETTINGS ##
|
|
||||||
|
|
||||||
sess = requests.Session()
|
|
||||||
sess.verify = False
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
|
||||||
|
|
||||||
sessionKey = sys.argv[1]
|
|
||||||
|
|
||||||
|
|
||||||
def send_notification(subject_text, body_text):
|
|
||||||
# Send the notification through Tautulli
|
|
||||||
payload = {'apikey': TAUTULLI_APIKEY,
|
|
||||||
'cmd': 'notify',
|
|
||||||
'notifier_id': NOTIFIER_ID,
|
|
||||||
'subject': subject_text,
|
|
||||||
'body': body_text}
|
|
||||||
|
|
||||||
try:
|
|
||||||
r = requests.post(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload)
|
|
||||||
response = r.json()
|
|
||||||
|
|
||||||
if response['response']['result'] == 'success':
|
|
||||||
sys.stdout.write("Successfully sent Tautulli notification.")
|
|
||||||
else:
|
|
||||||
raise Exception(response['response']['message'])
|
|
||||||
except Exception as e:
|
|
||||||
sys.stderr.write("Tautulli API 'notify' request failed: {0}.".format(e))
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def check_session(sessionKey):
|
|
||||||
for session in plex.sessions():
|
|
||||||
if session.sessionKey == int(sessionKey):
|
|
||||||
return session
|
|
||||||
|
|
||||||
|
|
||||||
def kill_stream(session, xtime, ntime):
|
|
||||||
state = session.players[0].state
|
|
||||||
username = session.usernames[0]
|
|
||||||
title = (session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title
|
|
||||||
|
|
||||||
if state == 'paused' and xtime == ntime:
|
|
||||||
if NOTIFIER_ID:
|
|
||||||
send_notification(SUBJECT_TEXT, BODY_TEXT.format(user=username, title=title))
|
|
||||||
session.stop(reason=KILL_MESSAGE)
|
|
||||||
return ntime
|
|
||||||
elif state in ('playing', 'buffering'):
|
|
||||||
sys.stdout.write("{user}'s stream of {title} is now {state}".format(user=username, title=title,
|
|
||||||
state=state))
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return xtime
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
startupinfo = None
|
|
||||||
if os.name == 'nt':
|
|
||||||
startupinfo = subprocess.STARTUPINFO()
|
|
||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
||||||
|
|
||||||
fileDir = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
sub_path = os.path.join(fileDir, sub_script)
|
|
||||||
|
|
||||||
for session in plex.sessions():
|
|
||||||
if session.sessionKey == int(sessionKey) and session.usernames[0] not in USER_IGNORE:
|
|
||||||
subprocess.Popen([sys.executable, sub_path, sessionKey, TIMEOUT, INTERVAL],
|
|
||||||
startupinfo=startupinfo)
|
|
@ -1,41 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
'''
|
|
||||||
wait_kill_pause_notify_main.py & wait_kill_pause_notify_sub.py should be in the same directory.
|
|
||||||
wait_kill_pause_notify_main.py executes sub_script wait_kill_pause_notify_sub.py.
|
|
||||||
|
|
||||||
Tautulli will timeout wait_kill_pause_notify_main.py after 30 seconds (default)
|
|
||||||
but wait_kill_pause_notify_sub.py will continue.
|
|
||||||
|
|
||||||
wait_kill_pause_notify_sub will check if the stream's session_id is still paused or if playing as restarted.
|
|
||||||
If playback is restarted then wait_kill_pause_notify_sub will stop and delete itself.
|
|
||||||
If stream remains paused then it will be killed and wait_kill_pause_notify_sub will stop.
|
|
||||||
Set TIMEOUT to max time before killing stream
|
|
||||||
Set INTERVAL to how often you want to check the stream status
|
|
||||||
'''
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from time import sleep
|
|
||||||
from wait_kill_pause_notify_main import kill_stream, check_session
|
|
||||||
|
|
||||||
sessionKey = int(sys.argv[1])
|
|
||||||
timeout = int(sys.argv[2])
|
|
||||||
interval = int(sys.argv[3])
|
|
||||||
|
|
||||||
x = 0
|
|
||||||
|
|
||||||
try:
|
|
||||||
print('Executing sub script.')
|
|
||||||
while x < timeout and x is not None:
|
|
||||||
sleep(interval)
|
|
||||||
if kill_stream(check_session(sessionKey), interval, timeout) is not None:
|
|
||||||
x += kill_stream(check_session(sessionKey), interval, timeout)
|
|
||||||
else:
|
|
||||||
print('Exiting sub script.')
|
|
||||||
exit(0)
|
|
||||||
print('Sub script initiating kill.')
|
|
||||||
kill_stream(check_session(sessionKey), timeout, timeout)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print('Error: {}'.format(e))
|
|
||||||
|
|
Reference in New Issue
Block a user