Created
March 5, 2017 20:37
-
-
Save JonnyWong16/1b1b02536e25002daf678946f513b950 to your computer and use it in GitHub Desktop.
Send a PlexPy notification when the total number of streams exceeds a threshold.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Description: Send a PlexPy notification when the total | |
# number of streams exceeds a threshold. | |
# Author: /u/SwiftPanda16 | |
# Requires: requests | |
# PlexPy script trigger: Playback start | |
# PlexPy script arguments: {streams} | |
import requests | |
import sys | |
### EDIT SETTINGS ### | |
PLEXPY_URL = 'http://localhost:8181' | |
PLEXPY_APIKEY = 'xxxxxxxxxx' | |
AGENT_ID = 10 # The PlexPy notifier agent id found here: https://github.com/JonnyWong16/plexpy/blob/master/API.md#notify | |
NOTIFY_SUBJECT = 'Subject' # The notification subject | |
NOTIFY_BODY = 'Body' # The notification body | |
STREAM_THRESHOLD = 5 | |
### CODE BELOW ### | |
def main(): | |
try: | |
streams = int(sys.argv[1]) | |
except: | |
print("Invalid PlexPy script argument passed.") | |
return | |
if streams >= STREAM_THRESHOLD: | |
print("Number of streams exceeds {threshold}.".format(threshold=STREAM_THRESHOLD)) | |
print("Sending PlexPy notification to agent ID: {agent_id}.".format(agent_id=AGENT_ID)) | |
params = {'apikey': PLEXPY_APIKEY, | |
'cmd': 'notify', | |
'agent_id': AGENT_ID, | |
'subject': NOTIFY_SUBJECT, | |
'body': NOTIFY_BODY} | |
r = requests.post(PLEXPY_URL.rstrip('/') + '/api/v2', params=params) | |
else: | |
print("Number of streams below {threshold}.".format(threshold=STREAM_THRESHOLD)) | |
print("No notification sent.") | |
return | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will this script work with Tautulli?