Skip to content

Commit d9c87d8

Browse files
committed
inital pmp workaround.
1 parent 4f5ce34 commit d9c87d8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

plexapi/client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
import time
33
import requests
44

55
from requests.status_codes import _codes as codes
@@ -70,6 +70,7 @@ def __init__(self, server=None, data=None, initpath=None, baseurl=None,
7070
self._session = session or server_session or requests.Session()
7171
self._proxyThroughServer = False
7272
self._commandId = 0
73+
self._last_call = 0
7374
if not any([data, initpath, baseurl, token]):
7475
self._baseurl = CONFIG.get('auth.client_baseurl', 'http://localhost:32433')
7576
self._token = logfilter.add_secret(CONFIG.get('auth.client_token'))
@@ -181,14 +182,26 @@ def sendCommand(self, command, proxy=None, **params):
181182
"""
182183
command = command.strip('/')
183184
controller = command.split('/')[0]
185+
headers = {'X-Plex-Target-Client-Identifier': self.machineIdentifier}
184186
if controller not in self.protocolCapabilities:
185187
log.debug('Client %s doesnt support %s controller.'
186188
'What your trying might not work' % (self.title, controller))
187189

190+
# Workaround for ptp. See https://github.com/pkkid/python-plexapi/issues/244
191+
t = time.time()
192+
if t - self._last_call >= 80 and self.product in ('ptp', 'Plex Media Player'):
193+
url = '/player/timeline/poll?wait=0&commandID=%s' % self._nextCommandId()
194+
if proxy:
195+
self._server.query(url, headers=headers)
196+
else:
197+
self.query(url, headers=headers)
198+
self._last_call = t
199+
188200
params['commandID'] = self._nextCommandId()
189201
key = '/player/%s%s' % (command, utils.joinArgs(params))
190-
headers = {'X-Plex-Target-Client-Identifier': self.machineIdentifier}
202+
191203
proxy = self._proxyThroughServer if proxy is None else proxy
204+
192205
if proxy:
193206
return self._server.query(key, headers=headers)
194207
return self.query(key, headers=headers)

0 commit comments

Comments
 (0)