Plex plugin

Posted on
Sat Dec 20, 2014 3:03 pm
ToonDoom offline
Posts: 36
Joined: Dec 20, 2014

Plex plugin

I've created a plugin for plex home theatre.

GitHub url is:

Source and binary:
https://github.com/ToonDoom/PlexPlugin/releases/tag/1.0


I'll add an attached with the plugin when I'm back at the Mac.

Currently it just monitors state of plex clients to allow triggers. For example when a movie/tv show is paused or played. I created this as my use case is to raise the light brightess when media is paused.

To use configure the url and port at the plugin level. Then add devices for each plex client. When adding a client you need to start playing media (can be paused) so that the plex client machine Id can be captured (the plex api only returns info on clients that are currently playing media).

You don't need plex pass to use this as they exposed this apis use to everyone a couple weeks back.
Last edited by ToonDoom on Sun Dec 28, 2014 4:00 am, edited 1 time in total.

Posted on
Sat Dec 20, 2014 3:11 pm
ToonDoom offline
Posts: 36
Joined: Dec 20, 2014

Re: Plex plugin

Ps be kind when looking at the code! This is my first foray into Python. Not a fan so far!

On a positive massive thumbs up to the indigo devs. creating this plugin was really pretty trivial and the flexibly that your app allows is very impressive.

Posted on
Sun Dec 21, 2014 12:04 am
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: Plex plugin

I put all of your code in a bundle named "Plex" since it didn't seem to download as one. I'm not sure if the name of the bundle is significant?
This isn't due to your plugin (I think) but do you have any insight into why an iPhone is considered a Server and not a Client? I attempted to add an iPhone as a Client device, but couldn't. I don't have any Clients; the Plex Media Server is on a remote MacMini and I access it through the web interface on my laptop.

Probably due to the lack of a machine identifier when attempting to add the device, but the log fills up with the following until the plugin is disabled. I'm not sure if this is intentional?
Code: Select all
  Plex HTPC Error                 Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 52, in runConcurrentThread
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/PlexPlugin.indigoPlugin/Contents/Server Plugin/plexapi.py", line 61, in getClientState
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/PlexPlugin.indigoPlugin/Contents/Server Plugin/plexapi.py", line 23, in getStatusSession
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/PlexPlugin.indigoPlugin/Contents/Server Plugin/plexapi.py", line 30, in callPlex
<type 'exceptions.TypeError'>: urlopen() got an unexpected keyword argument 'timeout'

  Plex HTPC Error                 plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)

Posted on
Sun Dec 21, 2014 1:07 am
ToonDoom offline
Posts: 36
Joined: Dec 20, 2014

Re: Plex plugin

I googled:

urlopen() got an unexpected keyword argument 'timeout'


The error appears to be an issue either with the version of python is running or the python install. Do you know what version you're running?

Until I can fix the above the machine id list will not be populated.

Posted on
Sun Dec 21, 2014 2:36 am
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: Plex plugin

I believe I read on one of the forums or in the wiki that Indigo runs it's own version of Python and it is capped at 2.5. Someone else can chime in and confirm.

Posted on
Sun Dec 21, 2014 8:59 am
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Plex plugin

The error appears to be an issue either with the version of python is running or the python install. Do you know what version you're running?

Indigo Plugins do run under Python 2.5 for all but Yosemite... but you can use the urlopen function -- it is just that the timeout parameter was added in Python 2.6. You should remove that argument call to urlopen (well, and any others after it that you may have added, in 2.5 you just have the URL and data parameters I believe) and that particular line of code should work.

Adam

Posted on
Sun Dec 21, 2014 9:39 am
ToonDoom offline
Posts: 36
Joined: Dec 20, 2014

Re: Plex plugin

Thanks for the confirmation. I'm running Yosemite so that's why it looked ok to me. Are people just running without a timeout or is there a 2.5 library that offers this?

Posted on
Sun Dec 21, 2014 9:40 am
ToonDoom offline
Posts: 36
Joined: Dec 20, 2014

Re: Plex plugin

Also what the best way to upload the plugin itself? I tried attaching here but no zips alowed.

Posted on
Sun Dec 21, 2014 9:44 am
ToonDoom offline
Posts: 36
Joined: Dec 20, 2014

Re: Plex plugin

I've removed the timeout param from github. Sorry for the noob but should I bump the plugin version for this?

Posted on
Sun Dec 21, 2014 10:12 am
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: Plex plugin

Yes, bump it anytime you have change(s) you want to push out. Indigo will only install (on double-click) a plugin if the version number is higher.

And thanks for the plugin contribution!

Image

Posted on
Sun Dec 21, 2014 10:18 am
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Plex plugin

Thanks for the confirmation. I'm running Yosemite so that's why it looked ok to me. Are people just running without a timeout or is there a 2.5 library that offers this?

I just let it run without an explicit timeout -- most of the other classes available (such as httplib) are either based off urllib or the timeout was added at the same version. I have no idea the default, but it will throw a timeout error so there is some value internally set. Just make sure you are doing it on a separate thread from the main server/GUI.

Adam

Posted on
Sun Dec 21, 2014 11:53 am
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: Plex plugin

New version seems to not throw errors every 10 sec. The version number (1.01) is the same according to the Indigo dialog box, but was enabled anyway? I changed the name of the plugin bundle to Plex HTPC. And it found my iPhone as a client, so a device is set and I set up a variable for the state. So all is working.

Posted on
Sun Dec 21, 2014 12:35 pm
ToonDoom offline
Posts: 36
Joined: Dec 20, 2014

Re: Plex plugin

Cool. Yeah I did not bump the version... Still learning;)

Can I host the plugin bundle here or do I need to host it myself? Git seems ok for source but can't find way to host assembly.

Posted on
Thu Jan 01, 2015 12:48 pm
hdfreak offline
Posts: 19
Joined: Jan 01, 2015

Re: Plex plugin

Wow--this is awesome. I use Plex and Insteon (and now Indigo) and this is exactly what I was hoping to be able to do.

THANK YOU for taking the time to work on this. Please set up a donation link on your download page so those of us finding it useful can contribute.

I do have a question regarding the "Client Offline" state. I'm trying to set up a trigger that kills the lights a few minutes after Plex Home Theater is closed (after we've left the theater room). So far I've had no luck. Doesn't do anything (in log even) when PHT is closed.

Thanks again--you made my day with this one.

Posted on
Sat Jan 03, 2015 9:23 am
ToonDoom offline
Posts: 36
Joined: Dec 20, 2014

Re: Plex plugin

Thanks for the feedback glad your getting some use out of the plugin :D

There are currently 4 states:

Server off line - Plex Media server is not responding to the request http://ip:port/status/sessions. Either the Plex media server is not running or the ip or port are incorrect

Client off line - This means that the client is not playing any media at the moment. /status/sessions returns the state from the plex media server perspective. So it does not seem to know when Plex home theatre is running only when it is playing media

Playing - media is being played

Paused - media is paused.

For your case non of the above will help. I will take a look at the plex api see if there is a way to determine if any client application is running rather than whether any media is being streamed.

Who is online

Users browsing this forum: No registered users and 9 guests