Skip to content

Commit 38b0fee

Browse files
committed
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 []
1 parent c2c13fb commit 38b0fee

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

plexapi/base.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,43 @@ def history(self, maxresults=9999999, mindate=None):
429429
"""
430430
return self._server.history(maxresults=maxresults, mindate=mindate, ratingKey=self.ratingKey)
431431

432+
def unmatch(self):
433+
""" Unmatches show object. """
434+
key = '/library/metadata/%s/unmatch' % self.ratingKey
435+
self._server.query(key, method=self._server._session.put)
436+
437+
def matches(self, auto=True, agent=None, title=None, year=None, language=None):
438+
""" Return list of show metadata matches from library agent. """
439+
key = '/library/metadata/%s/matches' % self.ratingKey
440+
if not auto:
441+
params = {'manual': 1,
442+
'title': title or self.title,
443+
'year': year or self.year if self.section().type != 'artist' else '',
444+
'language': language or self.section().language}
445+
if agent:
446+
agents = self._server.agents()
447+
match_agent = next((ag for ag in agents if ag.shortIdentifier == agent), None)
448+
if match_agent:
449+
params['agent'] = match_agent.identifier
450+
else:
451+
raise NotFound('Couldnt find "%s" in agents list (%s)' %
452+
(agent, ','.join(agents.keys())))
453+
else:
454+
params['agent'] = self.section().agent
455+
456+
key = key + '?' + urlencode(params)
457+
data = self._server.query(key, method=self._server._session.get)
458+
return self.findItems(data)
459+
460+
def fixMatch(self, searchResult):
461+
""" Use match result to update show metadata. """
462+
key = '/library/metadata/%s/match' % self.ratingKey
463+
params = {'guid': searchResult.guid,
464+
'name': searchResult.name}
465+
466+
data = key + '?' + urlencode(params)
467+
self._server.query(data, method=self._server._session.put)
468+
432469
# The photo tag cant be built atm. TODO
433470
# def arts(self):
434471
# part = '%s/arts' % self.key

0 commit comments

Comments
 (0)