Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add params parameter to request #1395

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions plexapi/base.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading