Skip to content

Commit 769239e

Browse files
author
朱校明
committed
feat: Add params parameter to request
1 parent 991c5e3 commit 769239e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

plexapi/base.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@ def _manuallyLoadXML(self, xml, cls=None):
170170
elem = ElementTree.fromstring(xml)
171171
return self._buildItemOrNone(elem, cls)
172172

173-
def fetchItems(self, ekey, cls=None, container_start=None, container_size=None, maxresults=None, **kwargs):
173+
def fetchItems(self,
174+
ekey,
175+
cls=None,
176+
container_start=None,
177+
container_size=None,
178+
maxresults=None,
179+
params=None,
180+
**kwargs):
174181
""" Load the specified key to find and build all items with the specified tag
175182
and attrs.
176183
@@ -186,6 +193,7 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
186193
container_start (None, int): offset to get a subset of the data
187194
container_size (None, int): How many items in data
188195
maxresults (int, optional): Only return the specified number of results.
196+
params (dict, optional): Any additional params to add to the request.
189197
**kwargs (dict): Optionally add XML attribute to filter the items.
190198
See the details below for more info.
191199
@@ -268,7 +276,7 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
268276
headers['X-Plex-Container-Start'] = str(container_start)
269277
headers['X-Plex-Container-Size'] = str(container_size)
270278

271-
data = self._server.query(ekey, headers=headers)
279+
data = self._server.query(ekey, headers=headers, params=params)
272280
subresults = self.findItems(data, cls, ekey, **kwargs)
273281
total_size = utils.cast(int, data.attrib.get('totalSize') or data.attrib.get('size')) or len(subresults)
274282

plexapi/server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def currentBackgroundProcess(self):
746746
""" Returns list of all :class:`~plexapi.media.TranscodeJob` objects running or paused on server. """
747747
return self.fetchItems('/status/sessions/background')
748748

749-
def query(self, key, method=None, headers=None, timeout=None, **kwargs):
749+
def query(self, key, method=None, headers=None, params=None, timeout=None, **kwargs):
750750
""" Main method used to handle HTTPS requests to the Plex server. This method helps
751751
by encoding the response to utf-8 and parsing the returned XML into and
752752
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):
756756
timeout = timeout or self._timeout
757757
log.debug('%s %s', method.__name__.upper(), url)
758758
headers = self._headers(**headers or {})
759-
response = method(url, headers=headers, timeout=timeout, **kwargs)
759+
response = method(url, headers=headers, params=params, timeout=timeout, **kwargs)
760760
if response.status_code not in (200, 201, 204):
761761
codename = codes.get(response.status_code)[0]
762762
errtext = response.text.replace('\n', ' ')

0 commit comments

Comments
 (0)