Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Created March 5, 2017 20:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonnyWong16/1b1b02536e25002daf678946f513b950 to your computer and use it in GitHub Desktop.
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.
#!/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()
@StarPoc
Copy link

StarPoc commented Mar 14, 2018

Will this script work with Tautulli?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment