adding unmatch/match methods from video:Movie and video:Show classes to base:PlexPartialObject

minor improvements to matches method thanks to @JonnyWong16
matching can be done for artists, albums, shows, movies
all other media types safely return an empty list []
This commit is contained in:
blacktwin 2020-03-13 22:22:30 -04:00
parent c2c13fbfe2
commit 38b0fee6c9

View file

@ -429,6 +429,43 @@ class PlexPartialObject(PlexObject):
"""
return self._server.history(maxresults=maxresults, mindate=mindate, ratingKey=self.ratingKey)
def unmatch(self):
""" Unmatches show object. """
key = '/library/metadata/%s/unmatch' % self.ratingKey
self._server.query(key, method=self._server._session.put)
def matches(self, auto=True, agent=None, title=None, year=None, language=None):
""" Return list of show metadata matches from library agent. """
key = '/library/metadata/%s/matches' % self.ratingKey
if not auto:
params = {'manual': 1,
'title': title or self.title,
'year': year or self.year if self.section().type != 'artist' else '',
'language': language or self.section().language}
if agent:
agents = self._server.agents()
match_agent = next((ag for ag in agents if ag.shortIdentifier == agent), None)
if match_agent:
params['agent'] = match_agent.identifier
else:
raise NotFound('Couldnt find "%s" in agents list (%s)' %
(agent, ','.join(agents.keys())))
else:
params['agent'] = self.section().agent
key = key + '?' + urlencode(params)
data = self._server.query(key, method=self._server._session.get)
return self.findItems(data)
def fixMatch(self, searchResult):
""" Use match result to update show metadata. """
key = '/library/metadata/%s/match' % self.ratingKey
params = {'guid': searchResult.guid,
'name': searchResult.name}
data = key + '?' + urlencode(params)
self._server.query(data, method=self._server._session.put)
# The photo tag cant be built atm. TODO
# def arts(self):
# part = '%s/arts' % self.key