|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | - |
| 2 | +import time |
3 | 3 | import requests |
4 | 4 |
|
5 | 5 | from requests.status_codes import _codes as codes |
@@ -70,6 +70,7 @@ def __init__(self, server=None, data=None, initpath=None, baseurl=None, |
70 | 70 | self._session = session or server_session or requests.Session() |
71 | 71 | self._proxyThroughServer = False |
72 | 72 | self._commandId = 0 |
| 73 | + self._last_call = 0 |
73 | 74 | if not any([data, initpath, baseurl, token]): |
74 | 75 | self._baseurl = CONFIG.get('auth.client_baseurl', 'http://localhost:32433') |
75 | 76 | self._token = logfilter.add_secret(CONFIG.get('auth.client_token')) |
@@ -181,14 +182,26 @@ def sendCommand(self, command, proxy=None, **params): |
181 | 182 | """ |
182 | 183 | command = command.strip('/') |
183 | 184 | controller = command.split('/')[0] |
| 185 | + headers = {'X-Plex-Target-Client-Identifier': self.machineIdentifier} |
184 | 186 | if controller not in self.protocolCapabilities: |
185 | 187 | log.debug('Client %s doesnt support %s controller.' |
186 | 188 | 'What your trying might not work' % (self.title, controller)) |
187 | 189 |
|
| 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 | + |
188 | 200 | params['commandID'] = self._nextCommandId() |
189 | 201 | key = '/player/%s%s' % (command, utils.joinArgs(params)) |
190 | | - headers = {'X-Plex-Target-Client-Identifier': self.machineIdentifier} |
| 202 | + |
191 | 203 | proxy = self._proxyThroughServer if proxy is None else proxy |
| 204 | + |
192 | 205 | if proxy: |
193 | 206 | return self._server.query(key, headers=headers) |
194 | 207 | return self.query(key, headers=headers) |
|
0 commit comments