Page 1 of 1

Plex Webhooks

Posted: Friday 12 May 2017 14:47
by Number8
Plex has a quite new feature named Plex Webhooks https://support.plex.tv/hc/en-us/articl ... 7-Webhooks that sends a JSON payload to a WebServer whenever certain things happen. So I am wondering how to (maybe) trigger an event upon the reception of the JSON payload and have some logic implemented idealy in Python to trigger specific actions. Any idea whether this could be achieved one way or another?
Thank you

Re: Plex Webhooks

Posted: Saturday 03 June 2017 3:56
by corbin

Re: Plex Webhooks

Posted: Saturday 03 June 2017 7:40
by Number8
Wow very impressed, thank you for sharing. On which platform are you running node.js?

Re: Plex Webhooks

Posted: Saturday 03 June 2017 9:24
by corbin
It's currently running on a Raspberry Pi 3, but was developed on my desktop PC running Windows 10. Should work on anything that can run Node.js

What I would like is a way to support multiple Plex servers, as when I watch something through a friends server this doesn't work, same as the Python scripts.

Re: Plex Webhooks

Posted: Sunday 04 June 2017 9:43
by Number8
I made this script to get various movie parameters based on movie title, works with two servers. There is a bit of french in it, nothing fancy that you could not understand

Code: Select all

# needs Python plex API @ https://github.com/mjs7231/python-plexapi
from plexapi.myplex import MyPlexAccount
import requests.packages.urllib3
import os

requests.packages.urllib3.disable_warnings()
account = MyPlexAccount.signin('yourUserID','yourPassword')
serveur = raw_input('Quel serveur? Paris [a], Saint Pierre [b] :')
if serveur == 'a':
    plex = account.resource('MEDIA').connect()  # returns a PlexServer instance
    
elif serveur == 'b':
    plex = account.resource('HTPC').connect()  # returns a PlexServer instance
else:
    print ('STOP')
    exit()

titre = 'start'
while titre <> '':
    titre = raw_input('Titre du film : ')
    try:
        video = plex.search(titre)[0]
        print('%s (%s) (%s) (%s)' % (video.title, video.year, video.media[0].aspectRatio, video.media[0].parts[0].file))
#        print('%s (%s) (%s) ' % (video.title, video.year, video.media[0].aspectRatio))
    except:
        if titre == '':
            print ('Exiting')
            exit
        else:
            print ('Titre de film inconnu')
 

Re: Plex Webhooks

Posted: Tuesday 06 June 2017 4:12
by corbin
Interesting, is this working by polling or event pushing?

Re: Plex Webhooks

Posted: Tuesday 06 June 2017 20:11
by Number8
Pooling, this is just a script. The library is really very interesting and makes easy to query any plex server. You have the github link at the beginning of the script. A bit slow though.

Re: Plex Webhooks

Posted: Friday 29 September 2017 13:39
by rathmannm
Hey Corbin,

I am trying to get this to work so that I can dim the lights whenever I start playing a movie in Plex. However I am struggling a bit as I am a complete noob when it comes to this.

I have Domoticz running on a Raspberry Pi and followed your installation instructions. I can run "node main.js" When I do I get a message saying "Express app running at http://localhost:80". So far so good but I am unsure about the webhook url and especially the port. Your instructions say "point to the server your are running main.js from". In my case my regular domoticz IP is 192.168.0.14 but which port do I use? Do I really use my internal IP or do I have to use my WAN IP for the webhook and setup some port forwarding?

Also once it is working am I right in thinking if I start playing a movie in Plex it simply creates a log entry? How do I create a subsequent trigger in Domoticz?

Sorry for all the questions but would really apprechiate if you could point me in the right direction!

Many thanks,
Manuel