mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
feat: Add params parameter to request (#1395)
* feat: Add params parameter to request * Update plexapi/base.py Co-authored-by: Dr.Blank <64108942+Dr-Blank@users.noreply.github.com> --------- Co-authored-by: 朱校明 <zhuxiaoming@dstcar.com> Co-authored-by: Dr.Blank <64108942+Dr-Blank@users.noreply.github.com>
This commit is contained in:
parent
d9be0e6f06
commit
0108c95bd8
2 changed files with 14 additions and 4 deletions
|
@ -170,7 +170,16 @@ class PlexObject:
|
||||||
elem = ElementTree.fromstring(xml)
|
elem = ElementTree.fromstring(xml)
|
||||||
return self._buildItemOrNone(elem, cls)
|
return self._buildItemOrNone(elem, cls)
|
||||||
|
|
||||||
def fetchItems(self, ekey, cls=None, container_start=None, container_size=None, maxresults=None, **kwargs):
|
def fetchItems(
|
||||||
|
self,
|
||||||
|
ekey,
|
||||||
|
cls=None,
|
||||||
|
container_start=None,
|
||||||
|
container_size=None,
|
||||||
|
maxresults=None,
|
||||||
|
params=None,
|
||||||
|
**kwargs,
|
||||||
|
):
|
||||||
""" Load the specified key to find and build all items with the specified tag
|
""" Load the specified key to find and build all items with the specified tag
|
||||||
and attrs.
|
and attrs.
|
||||||
|
|
||||||
|
@ -186,6 +195,7 @@ class PlexObject:
|
||||||
container_start (None, int): offset to get a subset of the data
|
container_start (None, int): offset to get a subset of the data
|
||||||
container_size (None, int): How many items in data
|
container_size (None, int): How many items in data
|
||||||
maxresults (int, optional): Only return the specified number of results.
|
maxresults (int, optional): Only return the specified number of results.
|
||||||
|
params (dict, optional): Any additional params to add to the request.
|
||||||
**kwargs (dict): Optionally add XML attribute to filter the items.
|
**kwargs (dict): Optionally add XML attribute to filter the items.
|
||||||
See the details below for more info.
|
See the details below for more info.
|
||||||
|
|
||||||
|
@ -268,7 +278,7 @@ class PlexObject:
|
||||||
headers['X-Plex-Container-Start'] = str(container_start)
|
headers['X-Plex-Container-Start'] = str(container_start)
|
||||||
headers['X-Plex-Container-Size'] = str(container_size)
|
headers['X-Plex-Container-Size'] = str(container_size)
|
||||||
|
|
||||||
data = self._server.query(ekey, headers=headers)
|
data = self._server.query(ekey, headers=headers, params=params)
|
||||||
subresults = self.findItems(data, cls, ekey, **kwargs)
|
subresults = self.findItems(data, cls, ekey, **kwargs)
|
||||||
total_size = utils.cast(int, data.attrib.get('totalSize') or data.attrib.get('size')) or len(subresults)
|
total_size = utils.cast(int, data.attrib.get('totalSize') or data.attrib.get('size')) or len(subresults)
|
||||||
|
|
||||||
|
|
|
@ -746,7 +746,7 @@ class PlexServer(PlexObject):
|
||||||
""" Returns list of all :class:`~plexapi.media.TranscodeJob` objects running or paused on server. """
|
""" Returns list of all :class:`~plexapi.media.TranscodeJob` objects running or paused on server. """
|
||||||
return self.fetchItems('/status/sessions/background')
|
return self.fetchItems('/status/sessions/background')
|
||||||
|
|
||||||
def query(self, key, method=None, headers=None, timeout=None, **kwargs):
|
def query(self, key, method=None, headers=None, params=None, timeout=None, **kwargs):
|
||||||
""" Main method used to handle HTTPS requests to the Plex server. This method helps
|
""" Main method used to handle HTTPS requests to the Plex server. This method helps
|
||||||
by encoding the response to utf-8 and parsing the returned XML into and
|
by encoding the response to utf-8 and parsing the returned XML into and
|
||||||
ElementTree object. Returns None if no data exists in the response.
|
ElementTree object. Returns None if no data exists in the response.
|
||||||
|
@ -756,7 +756,7 @@ class PlexServer(PlexObject):
|
||||||
timeout = timeout or self._timeout
|
timeout = timeout or self._timeout
|
||||||
log.debug('%s %s', method.__name__.upper(), url)
|
log.debug('%s %s', method.__name__.upper(), url)
|
||||||
headers = self._headers(**headers or {})
|
headers = self._headers(**headers or {})
|
||||||
response = method(url, headers=headers, timeout=timeout, **kwargs)
|
response = method(url, headers=headers, params=params, timeout=timeout, **kwargs)
|
||||||
if response.status_code not in (200, 201, 204):
|
if response.status_code not in (200, 201, 204):
|
||||||
codename = codes.get(response.status_code)[0]
|
codename = codes.get(response.status_code)[0]
|
||||||
errtext = response.text.replace('\n', ' ')
|
errtext = response.text.replace('\n', ' ')
|
||||||
|
|
Loading…
Reference in a new issue