From 1e8e96398b80e8f80a95127e11996756242f9c47 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Fri, 29 Jun 2018 13:14:13 -0700 Subject: [PATCH 1/3] Decode script arguments --- killstream/kill_stream.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/killstream/kill_stream.py b/killstream/kill_stream.py index 110da98..36111d2 100644 --- a/killstream/kill_stream.py +++ b/killstream/kill_stream.py @@ -52,6 +52,7 @@ TAUTULLI_URL = '' TAUTULLI_APIKEY = '' TAUTULLI_URL = os.getenv('TAUTULLI_URL', TAUTULLI_URL) TAUTULLI_APIKEY = os.getenv('TAUTULLI_APIKEY', TAUTULLI_APIKEY) +TAUTULLI_ENCODING = os.getenv('TAUTULLI_ENCODING', 'UTF-8') SUBJECT_TEXT = "Tautulli has killed a stream." BODY_TEXT = "Killed session ID '{id}'. Reason: {message}" @@ -241,6 +242,10 @@ def terminate_long_pause(session_id, message, limit, interval, notify=None): return +def arg_decoding(arg): + return arg.decode(TAUTULLI_ENCODING) + + if __name__ == "__main__": parser = argparse.ArgumentParser( description="Killing Plex streams from Tautulli.") @@ -248,7 +253,7 @@ if __name__ == "__main__": help='Kill selector.\nChoices: (%(choices)s)') parser.add_argument('--userId', type=int, 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.') parser.add_argument('--sessionId', required=True, help='The unique identifier for the stream.') @@ -259,7 +264,7 @@ if __name__ == "__main__": help='The time session is allowed to remain paused.') parser.add_argument('--interval', type=int, default=30, 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.') opts = parser.parse_args() From 2bd92acca728dfd7c478a0dcfe59f3af2ed77aa7 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Fri, 29 Jun 2018 23:50:42 -0700 Subject: [PATCH 2/3] Encode back to UTF-8 --- killstream/kill_stream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/killstream/kill_stream.py b/killstream/kill_stream.py index 36111d2..e927bc6 100644 --- a/killstream/kill_stream.py +++ b/killstream/kill_stream.py @@ -243,7 +243,7 @@ def terminate_long_pause(session_id, message, limit, interval, notify=None): def arg_decoding(arg): - return arg.decode(TAUTULLI_ENCODING) + return arg.decode(TAUTULLI_ENCODING).encode('UTF-8') if __name__ == "__main__": From c413526ec36f905dd24ed277bc3c6afd340a48d2 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Fri, 29 Jun 2018 23:58:24 -0700 Subject: [PATCH 3/3] Return empty list if get_activity fails --- killstream/kill_stream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/killstream/kill_stream.py b/killstream/kill_stream.py index e927bc6..d592924 100644 --- a/killstream/kill_stream.py +++ b/killstream/kill_stream.py @@ -125,7 +125,7 @@ def get_activity(): except Exception as e: sys.stderr.write( "Tautulli API 'get_activity' request failed: {0}.\n".format(e)) - pass + return [] def get_user_session_ids(user_id):