From 769239ec8c78272227aea5cc577a079b3f3458e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=A0=A1=E6=98=8E?= Date: Fri, 12 Apr 2024 18:57:32 +0800 Subject: [PATCH 1/2] feat: Add params parameter to request --- plexapi/base.py | 12 ++++++++++-- plexapi/server.py | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plexapi/base.py b/plexapi/base.py index 0852426d2..ca55ca156 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -170,7 +170,14 @@ 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. @@ -186,6 +193,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. @@ -268,7 +276,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) diff --git a/plexapi/server.py b/plexapi/server.py index bdd330f78..178ce82b6 100644 --- a/plexapi/server.py +++ b/plexapi/server.py @@ -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. @@ -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', ' ') From 339061b0fddb0142c43198c2134da9e7f30544f4 Mon Sep 17 00:00:00 2001 From: zhu0823 Date: Tue, 16 Apr 2024 16:41:32 +0800 Subject: [PATCH 2/2] Update plexapi/base.py Co-authored-by: Dr.Blank <64108942+Dr-Blank@users.noreply.github.com> --- plexapi/base.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plexapi/base.py b/plexapi/base.py index ca55ca156..edfbeda5d 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -170,14 +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, - params=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.