Add LibrarySection.hubSearch()

This commit is contained in:
JonnyWong16 2021-03-10 21:53:24 -08:00
parent 1429867ae5
commit 811f661576
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 16 additions and 7 deletions

View file

@ -319,8 +319,8 @@ class LibrarySection(PlexObject):
art (str): Background artwork used to respresent the library section.
composite (str): Composite image used to represent the library section.
createdAt (datetime): Datetime the library section was created.
filters (str): Unknown
key (str): Key (or ID) of this library section.
filters (bool): True if filters are available for the library section.
key (int): Key (or ID) of this library section.
language (str): Language represented in this section (en, xn, etc).
locations (List<str>): List of folder paths added to the library section.
refreshing (bool): True if this section is currently being refreshed.
@ -339,8 +339,8 @@ class LibrarySection(PlexObject):
self.art = data.attrib.get('art')
self.composite = data.attrib.get('composite')
self.createdAt = utils.toDatetime(data.attrib.get('createdAt'))
self.filters = data.attrib.get('filters')
self.key = data.attrib.get('key') # invalid key from plex
self.filters = utils.cast(bool, data.attrib.get('filters'))
self.key = utils.cast(int, data.attrib.get('key'))
self.language = data.attrib.get('language')
self.locations = self.listAttrs(data, 'path', etag='Location')
self.refreshing = utils.cast(bool, data.attrib.get('refreshing'))
@ -626,6 +626,12 @@ class LibrarySection(PlexObject):
key = '/library/sections/%s/%s%s' % (self.key, category, utils.joinArgs(args))
return self.fetchItems(key, cls=FilterChoice)
def hubSearch(self, query, mediatype=None, limit=None):
""" Returns the hub search results for this library. See :func:`~plexapi.server.PlexServer.search`
for details and parameters.
"""
return self._server.search(query, mediatype, limit, sectionId=self.key)
def search(self, title=None, sort=None, maxresults=None,
libtype=None, container_start=0, container_size=X_PLEX_CONTAINER_SIZE, **kwargs):
""" Search the library. The http requests will be batched in container_size. If you're only looking for the first <num>

View file

@ -512,7 +512,7 @@ class PlexServer(PlexObject):
data = response.text.encode('utf8')
return ElementTree.fromstring(data) if data.strip() else None
def search(self, query, mediatype=None, limit=None):
def search(self, query, mediatype=None, limit=None, sectionId=None):
""" Returns a list of media items or filter categories from the resulting
`Hub Search <https://www.plex.tv/blog/seek-plex-shall-find-leveling-web-app/>`_
against all items in your Plex library. This searches genres, actors, directors,
@ -526,10 +526,11 @@ class PlexServer(PlexObject):
Parameters:
query (str): Query to use when searching your library.
mediatype (str): Optionally limit your search to the specified media type.
mediatype (str, optional): Limit your search to the specified media type.
actor, album, artist, autotag, collection, director, episode, game, genre,
movie, photo, photoalbum, place, playlist, shared, show, tag, track
limit (int): Optionally limit to the specified number of results per Hub.
limit (int, optional): Limit to the specified number of results per Hub.
sectionId (int, optional): The section ID (key) of the library to search within.
"""
results = []
params = {
@ -538,6 +539,8 @@ class PlexServer(PlexObject):
'includeExternalMedia': 1}
if limit:
params['limit'] = limit
if sectionId:
params['sectionId'] = sectionId
key = '/hubs/search?%s' % urlencode(params)
for hub in self.fetchItems(key, Hub):
if mediatype: