Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Last active March 6, 2017 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonnyWong16/d508d8d5d1fcb336efc1a3d167eb7b1a to your computer and use it in GitHub Desktop.
Save JonnyWong16/d508d8d5d1fcb336efc1a3d167eb7b1a to your computer and use it in GitHub Desktop.
Send a PlexPy notification with the movie directors' IMDB page
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Description: Send a PlexPy notification with the directors' IMDB page.
# Author: /u/SwiftPanda16
# Requires: requests, imdbpie
# PlexPy script trigger: Playback stop
# PlexPy script arguments: "{title}" {imdb_id}
import requests
import sys
from imdbpie import Imdb
### EDIT SETTINGS ###
PLEXPY_URL = 'http://localhost:8181'
PLEXPY_APIKEY = 'xxxxxxxx'
AGENT_ID = 10 # The PlexPy notifier agent id found here: https://github.com/JonnyWong16/plexpy/blob/master/API.md#notify
NOTIFY_SUBJECT = 'Movie Directors for {title}' # The notification subject
NOTIFY_BODY = '{name}: {url}' # The notification body
### CODE BELOW ###
def main():
try:
title = sys.argv[1]
imdb_id = sys.argv[2]
except:
print("Invalid PlexPy script argument passed.")
return
if imdb_id:
try:
imdb = Imdb()
imdb_result = imdb.get_title_by_id(imdb_id)
except:
print("IMDB request failed.")
return
else:
print("No IMDB ID passed.")
print("Exiting script.")
return
directors = imdb_result.directors_summary
if directors:
print("Movie directors found on IMDB.")
body_text = []
for d in directors:
url = 'http://www.imdb.com/name/{imdb_id}'.format(imdb_id=d.imdb_id)
body_text.append(NOTIFY_BODY.format(name=d.name, url=url))
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.format(title=title),
'body': '\n'.join(body_text)}
r = requests.post(PLEXPY_URL.rstrip('/') + '/api/v2', params=params)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment