Skip to content

Commit 0108c95

Browse files
zhu0823朱校明Dr-Blank
authored
feat: Add params parameter to request (#1395)
* feat: Add params parameter to request * Update plexapi/base.py Co-authored-by: Dr.Blank <[email protected]> --------- Co-authored-by: 朱校明 <[email protected]> Co-authored-by: Dr.Blank <[email protected]>
1 parent d9be0e6 commit 0108c95

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

plexapi/base.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,16 @@ 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(
174+
self,
175+
ekey,
176+
cls=None,
177+
container_start=None,
178+
container_size=None,
179+
maxresults=None,
180+
params=None,
181+
**kwargs,
182+
):
174183
""" Load the specified key to find and build all items with the specified tag
175184
and attrs.
176185
@@ -186,6 +195,7 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
186195
container_start (None, int): offset to get a subset of the data
187196
container_size (None, int): How many items in data
188197
maxresults (int, optional): Only return the specified number of results.
198+
params (dict, optional): Any additional params to add to the request.
189199
**kwargs (dict): Optionally add XML attribute to filter the items.
190200
See the details below for more info.
191201
@@ -268,7 +278,7 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
268278
headers['X-Plex-Container-Start'] = str(container_start)
269279
headers['X-Plex-Container-Size'] = str(container_size)
270280

271-
data = self._server.query(ekey, headers=headers)
281+
data = self._server.query(ekey, headers=headers, params=params)
272282
subresults = self.findItems(data, cls, ekey, **kwargs)
273283
total_size = utils.cast(int, data.attrib.get('totalSize') or data.attrib.get('size')) or len(subresults)
274284

plexapi/server.py

Lines changed: 2 additions & 2 deletions
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)