mirror of
https://github.com/pkkid/python-plexapi
synced 2025-02-17 05:18:26 +00:00
Add preliminary session support
This commit is contained in:
parent
382a4f45aa
commit
b6569dc6a3
1 changed files with 8 additions and 2 deletions
|
@ -24,9 +24,10 @@ DEFAULT_BASEURI = 'http://localhost:32400'
|
||||||
|
|
||||||
class PlexServer(object):
|
class PlexServer(object):
|
||||||
|
|
||||||
def __init__(self, baseuri=None, token=None):
|
def __init__(self, baseuri=None, token=None, session=None):
|
||||||
self.baseuri = baseuri or DEFAULT_BASEURI
|
self.baseuri = baseuri or DEFAULT_BASEURI
|
||||||
self.token = token
|
self.token = token
|
||||||
|
self.session = session # set this as a requests.session to use that session
|
||||||
data = self._connect()
|
data = self._connect()
|
||||||
self.friendlyName = data.attrib.get('friendlyName')
|
self.friendlyName = data.attrib.get('friendlyName')
|
||||||
self.machineIdentifier = data.attrib.get('machineIdentifier')
|
self.machineIdentifier = data.attrib.get('machineIdentifier')
|
||||||
|
@ -80,10 +81,15 @@ class PlexServer(object):
|
||||||
headers['X-Plex-Token'] = self.token
|
headers['X-Plex-Token'] = self.token
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
def query(self, path, method=requests.get, **kwargs):
|
def query(self, path, method=None, **kwargs):
|
||||||
global TOTAL_QUERIES
|
global TOTAL_QUERIES
|
||||||
TOTAL_QUERIES += 1
|
TOTAL_QUERIES += 1
|
||||||
url = self.url(path)
|
url = self.url(path)
|
||||||
|
if method is None:
|
||||||
|
if self.session is not None:
|
||||||
|
method = self.session.get
|
||||||
|
else:
|
||||||
|
method = requests.get
|
||||||
log.info('%s %s', method.__name__.upper(), url)
|
log.info('%s %s', method.__name__.upper(), url)
|
||||||
response = method(url, headers=self.headers(), timeout=TIMEOUT, **kwargs)
|
response = method(url, headers=self.headers(), timeout=TIMEOUT, **kwargs)
|
||||||
if response.status_code not in [200, 201]:
|
if response.status_code not in [200, 201]:
|
||||||
|
|
Loading…
Add table
Reference in a new issue