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

Add people in searchDiscover response #1174

Closed
wants to merge 4 commits into from
Closed
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
83 changes: 44 additions & 39 deletions plexapi/myplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def tidal(self):
data = self.query(f'{self.MUSIC}/hubs')
return self.findItems(data)

def watchlist(self, filter=None, sort=None, libtype=None, maxresults=None, **kwargs):
def watchlist(self, filter=None, sort=None, libtype=None, language=None, maxresults=None, **kwargs):
""" Returns a list of :class:`~plexapi.video.Movie` and :class:`~plexapi.video.Show` items in the user's watchlist.
Note: The objects returned are from Plex's online metadata. To get the matching item on a Plex server,
search for the media using the guid.
Expand Down Expand Up @@ -915,7 +915,8 @@ def watchlist(self, filter=None, sort=None, libtype=None, maxresults=None, **kwa
"""
params = {
'includeCollections': 1,
'includeExternalMedia': 1
'includeExternalMedia': 1,
'X-Plex-language': language
}

if not filter:
Expand Down Expand Up @@ -1033,47 +1034,51 @@ def markUnplayed(self, item):
self.query(key, params=params)
return self

def searchDiscover(self, query, limit=30, libtype=None):
""" Search for movies and TV shows in Discover.
Returns a list of :class:`~plexapi.video.Movie` and :class:`~plexapi.video.Show` objects.
def searchDiscover(self, query, limit=30, libtype=None, language=None):
""" Search for movies, TV shows, and people in Discover.
Returns a list of :class:`~plexapi.video.Movie`, :class:`~plexapi.video.Show`, and :class:`to be updated` objects.

Parameters:
query (str): Search query.
limit (int, optional): Limit to the specified number of results. Default 30.
libtype (str, optional): 'movie' or 'show' to only return movies or shows, otherwise return all items.
"""
libtypes = {'movie': 'movies', 'show': 'tv'}
libtype = libtypes.get(libtype, 'movies,tv')
Parameters:
query (str): Search query.
limit (int, optional): Limit to the specified number of results. Default 30.
libtype (str, optional): 'movie', 'show', or 'people' to only return movies, shows, or people, otherwise return all items.
"""
libtypes = {'movie': 'movies', 'show': 'tv', 'people': 'people'}
libtype = libtypes.get(libtype, 'movies,tv,people')

headers = {
'Accept': 'application/json'
}
params = {
'query': query,
'limit': limit,
'searchTypes': libtype,
'includeMetadata': 1
}
headers = {
'Accept': 'application/json'
}
params = {
'query': query,
'limit': limit,
'searchTypes': libtype,
'includeMetadata': 1,
'filterPeople': 1,
'X-Plex-Language': language
}

data = self.query(f'{self.METADATA}/library/search', headers=headers, params=params)
searchResults = data['MediaContainer'].get('SearchResults', [])
searchResult = next((s.get('SearchResult', []) for s in searchResults if s.get('id') == 'external'), [])

results = []
for result in searchResult:
metadata = result['Metadata']
type = metadata['type']
if type == 'movie':
tag = 'Video'
elif type == 'show':
tag = 'Directory'
else:
continue
attrs = ''.join(f'{k}="{html.escape(str(v))}" ' for k, v in metadata.items())
xml = f'<{tag} {attrs}/>'
results.append(self._manuallyLoadXML(xml))
data = self.query(f'{self.METADATA}/library/search', headers=headers, params=params)
searchResults = data['MediaContainer'].get('SearchResults', [])
searchResult = [r for s in searchResults if s.get('id') in ['external', 'people'] for r in s.get('SearchResult', [])]

results = []
for result in searchResult:
metadata = result.get('Metadata') or result.get('Directory')
type = metadata['type']
if type == 'movie':
tag = 'Video'
elif type == 'show':
tag = 'Directory'
elif type == 'person':
tag = 'Directory' # Needs to be updated, maybe a new object Person should be created
else:
continue
attrs = ''.join(f'{k}="{html.escape(str(v))}" ' for k, v in metadata.items())
xml = f'<{tag} {attrs}/>'
results.append(self._manuallyLoadXML(xml))

return self._toOnlineMetadata(results)
return self._toOnlineMetadata(results)

@property
def viewStateSync(self):
Expand Down