Merge remote-tracking branch 'origin/master'

This commit is contained in:
Blacktwin 2018-07-09 08:30:38 -04:00
commit 8f92570a16
2 changed files with 22 additions and 17 deletions

View File

@ -52,6 +52,7 @@ TAUTULLI_URL = ''
TAUTULLI_APIKEY = '' TAUTULLI_APIKEY = ''
TAUTULLI_URL = os.getenv('TAUTULLI_URL', TAUTULLI_URL) TAUTULLI_URL = os.getenv('TAUTULLI_URL', TAUTULLI_URL)
TAUTULLI_APIKEY = os.getenv('TAUTULLI_APIKEY', TAUTULLI_APIKEY) TAUTULLI_APIKEY = os.getenv('TAUTULLI_APIKEY', TAUTULLI_APIKEY)
TAUTULLI_ENCODING = os.getenv('TAUTULLI_ENCODING', 'UTF-8')
SUBJECT_TEXT = "Tautulli has killed a stream." SUBJECT_TEXT = "Tautulli has killed a stream."
BODY_TEXT = "Killed session ID '{id}'. Reason: {message}" BODY_TEXT = "Killed session ID '{id}'. Reason: {message}"
@ -124,7 +125,7 @@ def get_activity():
except Exception as e: except Exception as e:
sys.stderr.write( sys.stderr.write(
"Tautulli API 'get_activity' request failed: {0}.\n".format(e)) "Tautulli API 'get_activity' request failed: {0}.\n".format(e))
pass return []
def get_user_session_ids(user_id): def get_user_session_ids(user_id):
@ -241,6 +242,10 @@ def terminate_long_pause(session_id, message, limit, interval, notify=None):
return return
def arg_decoding(arg):
return arg.decode(TAUTULLI_ENCODING).encode('UTF-8')
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Killing Plex streams from Tautulli.") description="Killing Plex streams from Tautulli.")
@ -248,7 +253,7 @@ if __name__ == "__main__":
help='Kill selector.\nChoices: (%(choices)s)') help='Kill selector.\nChoices: (%(choices)s)')
parser.add_argument('--userId', type=int, parser.add_argument('--userId', type=int,
help='The unique identifier for the user.') help='The unique identifier for the user.')
parser.add_argument('--username', parser.add_argument('--username', type=arg_decoding,
help='The username of the person streaming.') help='The username of the person streaming.')
parser.add_argument('--sessionId', required=True, parser.add_argument('--sessionId', required=True,
help='The unique identifier for the stream.') help='The unique identifier for the stream.')
@ -259,7 +264,7 @@ if __name__ == "__main__":
help='The time session is allowed to remain paused.') help='The time session is allowed to remain paused.')
parser.add_argument('--interval', type=int, default=30, parser.add_argument('--interval', type=int, default=30,
help='The seconds between paused session checks.') help='The seconds between paused session checks.')
parser.add_argument('--killMessage', nargs='+', parser.add_argument('--killMessage', nargs='+', type=arg_decoding,
help='Message to send to user whose stream is killed.') help='Message to send to user whose stream is killed.')
opts = parser.parse_args() opts = parser.parse_args()

View File

@ -11,7 +11,7 @@ Conditions: \[ `Transcode Decision` | `is` | `transcode` \]
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage Transcoding streams are not allowed. --jbop stream --username {username} --sessionId {session_id} --killMessage 'Transcoding streams are not allowed.'
``` ```
### Kill non-local streams paused for a long time ### Kill non-local streams paused for a long time
@ -24,7 +24,7 @@ Conditions: \[ `Stream Local` | `is not` | `1` \]
Arguments: Arguments:
``` ```
--jbop paused --sessionId {session_id} --killMessage Your stream was paused for over 20 minutes and has been automatically stopped for you. --jbop paused --sessionId {session_id} --killMessage 'Your stream was paused for over 20 minutes and has been automatically stopped for you.'
``` ```
### Kill streams paused for a custom time ### Kill streams paused for a custom time
@ -36,7 +36,7 @@ Triggers: Playback Paused
Arguments: Arguments:
``` ```
--jbop paused --interval 15 --limit 300 --sessionId {session_id} --killMessage Your stream was paused for over 5 minutes and has been automatically stopped for you. --jbop paused --interval 15 --limit 300 --sessionId {session_id} --killMessage 'Your stream was paused for over 5 minutes and has been automatically stopped for you.'
``` ```
### Kill paused transcodes ### Kill paused transcodes
@ -46,7 +46,7 @@ Conditions: \[ `Transcode Decision` | `is` | `transcode` \]
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage Paused streams are automatically stopped. --jbop stream --username {username} --sessionId {session_id} --killMessage 'Paused streams are automatically stopped.'
``` ```
### Limit User stream count, kill last stream ### Limit User stream count, kill last stream
@ -56,7 +56,7 @@ Conditions: \[ `User Streams` | `is greater than` | `3` \]
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage You are only allowed 3 streams. --jbop stream --username {username} --sessionId {session_id} --killMessage 'You are only allowed 3 streams.'
``` ```
### IP Whitelist ### IP Whitelist
@ -66,7 +66,7 @@ Conditions: \[ `IP Address` | `is not` | `192.168.0.100 or 192.168.0.101` \]
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage {ip_address} is not allowed to access {server_name}. --jbop stream --username {username} --sessionId {session_id} --killMessage '{ip_address} is not allowed to access {server_name}.'
``` ```
### Kill by platform ### Kill by platform
@ -76,7 +76,7 @@ Conditions: \[ `Platform` | `is` | `Roku or Android` \]
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage {platform} is not allowed on {server_name}. --jbop stream --username {username} --sessionId {session_id} --killMessage '{platform} is not allowed on {server_name}.'
``` ```
### Kill transcode by library ### Kill transcode by library
@ -88,7 +88,7 @@ Conditions:
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage Transcoding streams are not allowed from the 4K Movies library. --jbop stream --username {username} --sessionId {session_id} --killMessage 'Transcoding streams are not allowed from the 4K Movies library.'
``` ```
### Kill transcode by original resolution ### Kill transcode by original resolution
@ -100,7 +100,7 @@ Conditions:
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage Transcoding streams are not allowed for {stream_video_resolution}p streams. --jbop stream --username {username} --sessionId {session_id} --killMessage 'Transcoding streams are not allowed for {stream_video_resolution}p streams.'
``` ```
### Kill transcode by bitrate ### Kill transcode by bitrate
@ -112,7 +112,7 @@ Conditions:
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage Transcoding streams are not allowed from over 4 Mbps (Yours: {stream_bitrate}). --jbop stream --username {username} --sessionId {session_id} --killMessage 'Transcoding streams are not allowed from over 4 Mbps (Yours: {stream_bitrate}).'
``` ```
### Kill by hours of the day ### Kill by hours of the day
@ -123,7 +123,7 @@ Triggers: Playback Start
Conditions: \[ `Timestamp` | `begins with` | `09 or 10` \] Conditions: \[ `Timestamp` | `begins with` | `09 or 10` \]
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage {server_name} is unavailable between 9 and 10 AM. --jbop stream --username {username} --sessionId {session_id} --killMessage '{server_name} is unavailable between 9 and 10 AM.'
``` ```
### Kill non local streams ### Kill non local streams
@ -132,7 +132,7 @@ Triggers: Playback Start
Conditions: \[ `Stream Local` | `is not` | `1` \] Conditions: \[ `Stream Local` | `is not` | `1` \]
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --killMessage {server_name} only allows local streams. --jbop stream --username {username} --sessionId {session_id} --killMessage '{server_name} only allows local streams.'
``` ```
### Kill transcodes and send a notification to agent 1 ### Kill transcodes and send a notification to agent 1
@ -142,7 +142,7 @@ Conditions: \[ `Transcode Decision` | `is` | `transcode` \]
Arguments: Arguments:
``` ```
--jbop stream --username {username} --sessionId {session_id} --notify 1 --killMessage Transcoding streams are not allowed. --jbop stream --username {username} --sessionId {session_id} --notify 1 --killMessage 'Transcoding streams are not allowed.'
``` ```
### Kill transcodes using the default message ### Kill transcodes using the default message
@ -162,5 +162,5 @@ Conditions: \[ `Username` | `is` | `Bob` \]
Arguments: Arguments:
``` ```
--jbop allStreams --userId {user_id} --notify 1 --killMessage Hey Bob, we need to talk! --jbop allStreams --userId {user_id} --notify 1 --killMessage 'Hey Bob, we need to talk!'
``` ```