Plex Status - Video, Audio, Photo, Play Progress

Python and python framework

Moderator: leecollings

racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Ah i see. No my server is not Plex Home Enabled. It should be quite easy to enable support with help.
Does it work if you include the token in the url?

Code: Select all

http://localhost:32400/status/sessions/?X-Plex-Token=YOURTOKENVALUEHERE
BoelShit
Posts: 10
Joined: Sunday 14 February 2016 11:18
Target OS: Windows
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by BoelShit »

Yup then the script works like a charm :D...
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Great! I'll make the necessary changes :)
EDIT: Script has been updated with Plex Home support. Now also clears the dummy device log when state="stopped"
MAidEN
Posts: 17
Joined: Sunday 07 December 2014 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by MAidEN »

Hi guys!

I have a problem with this script, when I launch manualy he doesn't finish :

Code: Select all

pi@raspberrypi ~/domoticz/scripts/python $ sudo ./plex.py
13:23:00- Seems to be an old file, ignoring.
IDLE
IDLE
He create variables, and update widget with "No Media Playing".

When I stop it i have this message :

Code: Select all

^CTraceback (most recent call last):
  File "./plex.py", line 389, in <module>
    time.sleep (plex_Interval)
KeyboardInterrupt
Can you help me?
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Actually it is working correctly. proven by the fact you get the IDLE message twice and the variables are created.
The script never finishes actually. it's constantly running. This is normal.
when you stop the script you get a message that you interrupted the script. It is not an error.
MAidEN
Posts: 17
Joined: Sunday 07 December 2014 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by MAidEN »

Ok but I have launch a video on my plex server, the result of script can't be "IDLE"...
BoelShit
Posts: 10
Joined: Sunday 14 February 2016 11:18
Target OS: Windows
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by BoelShit »

racquemis wrote:Great! I'll make the necessary changes :)
EDIT: Script has been updated with Plex Home support. Now also clears the dummy device log when state="stopped"
Thanks! You were faster :P
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

MAidEN wrote:Ok but I have launch a video on my plex server, the result of script can't be "IDLE"...
Two IDLE messages in a row are only generated when the script is first started and there is no media playing or when you misconfigured the script.
How are you calling the script?
As a test run the script from a terminal. Leave it running and then start a movie or episode. You should see the status updates be printed on the terminal. If it doesn't it could be possible you made a typo in the Plex IP, or port. Both must match your Plex Server.
MAidEN
Posts: 17
Joined: Sunday 07 December 2014 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by MAidEN »

I was launch the script manualy for test.
I start movie after, but i don't have any update.
My plex IP and port are good...
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Have you set name of the plex client the script must listen for? That is one likely explanation for it not working.
If you have not changed it it will listen to my devices (OpenELEC-PHT And Jasper-TPC). When you have changed it, Don't forget to specify the corresponding text dummy IDX.

Code: Select all

dom_PlexPlayers        = ['OpenELEC-PHT','Jasper-TPC'] #Players not on this list will be ignored
dom_PlexPlayInfo_ID    = ['24','30']
Just expand the array if you have more then two plex clients in your home.
kiwi
Posts: 14
Joined: Thursday 28 January 2016 13:41
Target OS: Linux
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by kiwi »

Hi,

Just a quick update, I have changed line 159 to:

Code: Select all

print 'Episode ' + state.capitalize() + ': ' + parenttitle + " - " + videotitle.encode('utf-8') + PlayProgress
Since videotitle can be non ascii...

Regards,
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

You are running an old version of the script. That particular line is no longer present in the script.
bran2000
Posts: 60
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by bran2000 »

same problem than Maiden even i changed the name and the idx, this is the error i got :
pi@DomoticzSam ~/domoticz/scripts $ ./plex2.py
23:28:14- Seems to be an old file, ignoring.
IDLE
IDLE

always no media playing ...
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Double check again. The script is working fine when the correct name of the player is specified.
Try changing the name of your plex client, and make sure the script is changed accordingly. It should work.

If it doesnt work:
Please give me the following:
1) the text shown when playing media at the url http:///<PLEXSERVERIP>:32400/status/sessions
2) your configuration from the script.
MaXa
Posts: 6
Joined: Saturday 15 August 2015 9:10
Target OS: Linux
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by MaXa »

I've upgraded to this version. It shows some output in the console like this:

Code: Select all

Paused Movie: -2012-720p (0:01:39/0:06:44)
Paused Movie: Sam Smith (0:13:18/1:02:32)
Playing Episode: Mad Men - Time Zones (0:05:16/0:47:39)
Paused Movie: -2012-720p (0:01:39/0:06:44)
Paused Movie: Sam Smith (0:13:18/1:02:32)
Playing Episode: Mad Men - Time Zones (0:05:16/0:47:39)
Traceback (most recent call last):
  File "./plextest.py", line 104, in <module>
    test = urllib2.urlopen(requestURL,timeout = 5).read()
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1187, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/lib/python2.7/httplib.py", line 1051, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 415, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 371, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
timeout: timed out
None
Paused Movie: -2012-720p (0:01:39/0:06:44)
Paused Movie: Sam Smith (0:13:18/1:02:32)
Playing Episode: Mad Men - Time Zones (0:05:26/0:47:39)
Is that okay? Seems like script behaviour is a little bit slower too which makes senses, because of the extra output and timeout message.
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

It looks okay. You do seem to have some connection problems due to the timeouts. If your plex server under heavy load? You could try decreasing the timeouts from 5 seconds to for example 1 second. Won't fix the timeout issue but the script will not slow down so much.

As for the speed of the script itself:
This script will check the plex sessions for changes every 5 seconds. The plex server updates the sessions every 10 seconds. Polling any faster wouldn't make sense.
cattoo
Posts: 60
Joined: Sunday 20 September 2015 17:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Sweden
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by cattoo »

Okey, now i have some issues again. The script is almost working.
It shows in the TEXT that the is "action". But it does not give me some variables.
Ive put the @reboot .... in crontab, given the plex.py 775 rights, striped the pid form the plex.py file. but it does not give me any varibles, unless i run the script manually.
Please help
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Have you reboot the raspberry pi? you've added @reboot in crontab. You need to reboot for the script to start automatically.
For the problem with your variables, please show me how your script settings look like. put it in

Code: Select all

 tags
cattoo
Posts: 60
Joined: Sunday 20 September 2015 17:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Sweden
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by cattoo »

racquemis wrote:Have you reboot the raspberry pi? you've added @reboot in crontab. You need to reboot for the script to start automatically.
For the problem with your variables, please show me how your script settings look like. put it in code tags
Yes the Pi is rebooted many times and the @reboot is placed in the crontab. Just checked again to be sure.

Code: Select all


#general Script settings
plex_Interval                 = 5     # Poll Interval. The Plex Server updates the session status every 10 seconds. Leave at 5 to not mis any state change.
plex_ShowPlayProgress         = True 
plex_AutoClearPlayLog         = True  # Should be enabled when showing Play Progress
plex_AutoCreateUserVariables  = True  # Automatically create a user variable for each Client listed under dom_PlexPlayers
plex_ViewOffsetTimeout        = 15    # In seconds.
plex_MaxErrorCount            = 3     # number of consecutive errors until Plex is considered Offline

#RunState values (for user variable)
plex_ServerOffline    = -1
plex_Idle             = 0
plex_Video_Playing    = 1
plex_Video_Paused     = 2
plex_Video_Stopped    = 3
plex_Video_Buffering  = 4
plex_Audio_Playing    = 11
plex_Audio_Paused     = 12
plex_Audio_Stopped    = 13
plex_Audio_Buffering  = 14

#Plex Server Settings
plexIP                 = '192.168.1.20'
plexPort               = '32400'          # (default port = 32400)
plexToken              = ''               # (Fill in when using Plex Home. To Retrieve Token: https://support.plex.tv/hc/en-us/articles/204059436-Finding-your-account-token-X-Plex-Token)

#domoticz settings
domoticz_host          = '192.168.1.70'
domoticz_port          = '8080'
domoticz_url           = 'json.htm'

#Translation Array - It's also possible to specify custom search strings. Place them at the beginning of the array.
transl_search    = ['Playing','Stopped','Buffering','Paused','Video','Movie','Episode','Clip','Audio','Slideshow']
transl_replace    = ['','','','','','','','','',''] #place replacement string on the same index as the search string. empty strings are not processed.

#Plex Players Settings - This script handles multiple players
dom_PlexPlayers        = ['TV UE55JU7000'] #Players not on this list will be ignored
dom_PlexPlayInfo_ID    = ['80']
dom_PlexPlayState_ID   = ['','']          # Name of User Variable. Is overwrriten when plex_AutoCreateUserVariables=True

racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Nothing wrong with the settings.
You say the script works when you run it manually but not from the crontab, double check the path to the script in the crontab. try navigating to it manually. The only thing i can think of is that the path to the script could be incorrect.

EDIT: There was an error on the main page that specified the crontab line. it said:

Code: Select all

@reboot python /home/pi/domoticz/scripts/plex.py &
while it should have been

Code: Select all

@reboot python /home/pi/domoticz/scripts/python/plex.py &
Could this be your problem?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests