Skip to content

Commit

Permalink
feat: Add params parameter to request (#1395)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Apr 19, 2024
1 parent d9be0e6 commit 0108c95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions plexapi/base.py
Expand Up @@ -170,7 +170,16 @@ def _manuallyLoadXML(self, xml, cls=None):
elem = ElementTree.fromstring(xml)
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
and attrs.
Expand All @@ -186,6 +195,7 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
container_start (None, int): offset to get a subset of the data
container_size (None, int): How many items in data
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.
See the details below for more info.
Expand Down Expand Up @@ -268,7 +278,7 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
headers['X-Plex-Container-Start'] = str(container_start)
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)
total_size = utils.cast(int, data.attrib.get('totalSize') or data.attrib.get('size')) or len(subresults)

Expand Down
4 changes: 2 additions & 2 deletions plexapi/server.py
Expand Up @@ -746,7 +746,7 @@ def currentBackgroundProcess(self):
""" Returns list of all :class:`~plexapi.media.TranscodeJob` objects running or paused on server. """
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
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.
Expand All @@ -756,7 +756,7 @@ def query(self, key, method=None, headers=None, timeout=None, **kwargs):
timeout = timeout or self._timeout
log.debug('%s %s', method.__name__.upper(), url)
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):
codename = codes.get(response.status_code)[0]
errtext = response.text.replace('\n', ' ')
Expand Down

0 comments on commit 0108c95

Please sign in to comment.