Plex Webhooks

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

Post Reply
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Plex Webhooks

Post 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
Debian buster on NUC and three RPi with buster.
User avatar
corbin
Posts: 463
Joined: Saturday 20 August 2016 22:57
Target OS: Windows
Domoticz version: Beta
Location: Brisbane, Australia
Contact:

Re: Plex Webhooks

Post by corbin »

Question about the Xiaomi Gateway in Domoticz? Please check the Wiki first: https://www.domoticz.com/wiki/Xiaomi_Gateway_(Aqara)
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Plex Webhooks

Post by Number8 »

Wow very impressed, thank you for sharing. On which platform are you running node.js?
Debian buster on NUC and three RPi with buster.
User avatar
corbin
Posts: 463
Joined: Saturday 20 August 2016 22:57
Target OS: Windows
Domoticz version: Beta
Location: Brisbane, Australia
Contact:

Re: Plex Webhooks

Post 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.
Question about the Xiaomi Gateway in Domoticz? Please check the Wiki first: https://www.domoticz.com/wiki/Xiaomi_Gateway_(Aqara)
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Plex Webhooks

Post 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')
 
Debian buster on NUC and three RPi with buster.
User avatar
corbin
Posts: 463
Joined: Saturday 20 August 2016 22:57
Target OS: Windows
Domoticz version: Beta
Location: Brisbane, Australia
Contact:

Re: Plex Webhooks

Post by corbin »

Interesting, is this working by polling or event pushing?
Question about the Xiaomi Gateway in Domoticz? Please check the Wiki first: https://www.domoticz.com/wiki/Xiaomi_Gateway_(Aqara)
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Plex Webhooks

Post 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.
Debian buster on NUC and three RPi with buster.
rathmannm
Posts: 15
Joined: Sunday 10 January 2016 18:56
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: Plex Webhooks

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest