Page 4 of 6

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

Posted: Sunday 14 February 2016 12:22
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

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

Posted: Sunday 14 February 2016 12:37
by BoelShit
Yup then the script works like a charm :D...

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

Posted: Sunday 14 February 2016 12:39
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"

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

Posted: Sunday 14 February 2016 13:26
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?

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

Posted: Sunday 14 February 2016 13:43
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.

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

Posted: Sunday 14 February 2016 13:45
by MAidEN
Ok but I have launch a video on my plex server, the result of script can't be "IDLE"...

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

Posted: Sunday 14 February 2016 13:47
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

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

Posted: Monday 15 February 2016 8:13
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.

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

Posted: Monday 15 February 2016 11:09
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...

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

Posted: Monday 15 February 2016 14:07
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.

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

Posted: Sunday 21 February 2016 10:08
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,

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

Posted: Sunday 21 February 2016 11:30
by racquemis
You are running an old version of the script. That particular line is no longer present in the script.

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

Posted: Monday 04 April 2016 23:32
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 ...

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

Posted: Tuesday 05 April 2016 11:27
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.

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

Posted: Saturday 09 April 2016 22:32
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.

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

Posted: Tuesday 12 April 2016 10:40
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.

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

Posted: Tuesday 26 July 2016 15:19
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

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

Posted: Thursday 28 July 2016 13:46
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

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

Posted: Thursday 28 July 2016 13:56
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


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

Posted: Friday 29 July 2016 8:20
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?