mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-29 07:00:19 +00:00
Simplify query calls, fix proxy bug
This commit is contained in:
parent
23a5ad695b
commit
8f329f53d7
1 changed files with 8 additions and 12 deletions
|
@ -187,32 +187,28 @@ class PlexClient(PlexObject):
|
||||||
log.debug('Client %s doesnt support %s controller.'
|
log.debug('Client %s doesnt support %s controller.'
|
||||||
'What your trying might not work' % (self.title, controller))
|
'What your trying might not work' % (self.title, controller))
|
||||||
|
|
||||||
|
proxy = self._proxyThroughServer if proxy is None else proxy
|
||||||
|
query = self._server.query if proxy else self.query
|
||||||
|
|
||||||
# Workaround for ptp. See https://github.com/pkkid/python-plexapi/issues/244
|
# Workaround for ptp. See https://github.com/pkkid/python-plexapi/issues/244
|
||||||
t = time.time()
|
t = time.time()
|
||||||
if t - self._last_call >= 80 and self.product in ('ptp', 'Plex Media Player'):
|
if t - self._last_call >= 80 and self.product in ('ptp', 'Plex Media Player'):
|
||||||
url = '/player/timeline/poll?wait=0&commandID=%s' % self._nextCommandId()
|
url = '/player/timeline/poll?wait=0&commandID=%s' % self._nextCommandId()
|
||||||
if proxy:
|
query(url, headers=headers)
|
||||||
self._server.query(url, headers=headers)
|
|
||||||
else:
|
|
||||||
self.query(url, headers=headers)
|
|
||||||
self._last_call = t
|
self._last_call = t
|
||||||
|
|
||||||
params['commandID'] = self._nextCommandId()
|
params['commandID'] = self._nextCommandId()
|
||||||
key = '/player/%s%s' % (command, utils.joinArgs(params))
|
key = '/player/%s%s' % (command, utils.joinArgs(params))
|
||||||
|
|
||||||
proxy = self._proxyThroughServer if proxy is None else proxy
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if proxy:
|
return query(key, headers=headers)
|
||||||
return self._server.query(key, headers=headers)
|
|
||||||
return self.query(key, headers=headers)
|
|
||||||
except ElementTree.ParseError:
|
except ElementTree.ParseError:
|
||||||
# Workaround for players which don't return valid XML on successful commands
|
# Workaround for players which don't return valid XML on successful commands
|
||||||
# - Plexamp: `b'OK'`
|
# - Plexamp: `b'OK'`
|
||||||
if self.product not in ('Plexamp'):
|
if self.product in ('Plexamp'):
|
||||||
|
return None
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def url(self, key, includeToken=False):
|
def url(self, key, includeToken=False):
|
||||||
""" Build a URL string with proper token argument. Token will be appended to the URL
|
""" Build a URL string with proper token argument. Token will be appended to the URL
|
||||||
if either includeToken is True or CONFIG.log.show_secrets is 'true'.
|
if either includeToken is True or CONFIG.log.show_secrets is 'true'.
|
||||||
|
|
Loading…
Reference in a new issue