@@ -433,6 +433,90 @@ def history(self, maxresults=9999999, mindate=None):
433433 """
434434 return self ._server .history (maxresults = maxresults , mindate = mindate , ratingKey = self .ratingKey )
435435
436+ def unmatch (self ):
437+ """ Unmatches metadata match from object. """
438+ key = '/library/metadata/%s/unmatch' % self .ratingKey
439+ self ._server .query (key , method = self ._server ._session .put )
440+
441+ def matches (self , auto = False , agent = None , title = None , year = None , language = None ):
442+ """ Return list of (:class:`~plexapi.media.SearchResult) metadata matches.
443+
444+ Parameters:
445+ auto (bool): True searches for matches automatically
446+ False allows for user to provide additional parameters to search
447+ *Auto searching
448+ agent (str): Agent name to be used (imdb, thetvdb, themoviedb, etc.)
449+ title (str): Title of item to search for
450+ year (str): Year of item to search in
451+ language (str) : Language of item to search in
452+
453+ Examples:
454+ 1. video.matches()
455+ 2. video.matches(title="something", year=2020)
456+ 3. video.matches(title="something")
457+ 4. video.matches(year=2020)
458+ 5. video.matches(title="something", year="")
459+ 6. video.matches(title="", year=2020)
460+ 7. video.matches(title="", year="")
461+
462+ 1. The default behaviour in Plex Web = no params in plexapi
463+ 2. Both title and year specified by user
464+ 3. Year automatically filled in
465+ 4. Title automatically filled in
466+ 5. Explicitly searches for title with blank year
467+ 6. Explicitly searches for blank title with year
468+ 7. I don't know what the user is thinking... return the same result as 1
469+
470+ For 2 to 7, the agent and language is automatically filled in
471+ """
472+ key = '/library/metadata/%s/matches' % self .ratingKey
473+ params = {'manual' : 1 }
474+
475+ if any ([agent , title , year , language ]):
476+ if title is None :
477+ params ['title' ] = self .title
478+ else :
479+ params ['title' ] = title
480+
481+ if year is None :
482+ params ['year' ] = self .year
483+ else :
484+ params ['year' ] = year
485+
486+ params ['language' ] = language or self .section ().language
487+
488+ if agent is None :
489+ params ['agent' ] = self .section ().agent
490+ else :
491+ params ['agent' ] = utils .getAgentIdentifier (self .section (), agent )
492+
493+ key = key + '?' + urlencode (params )
494+ data = self ._server .query (key , method = self ._server ._session .get )
495+ return self .findItems (data )
496+
497+ def fixMatch (self , searchResult = None , auto = False ):
498+ """ Use match result to update show metadata.
499+
500+ Parameters:
501+ auto (bool): True uses first match from matches
502+ False allows user to provide the match
503+ *Auto matching
504+ searchResult (:class:`~plexapi.media.SearchResult): Search result from
505+ ~plexapi.base.matches()
506+ """
507+ key = '/library/metadata/%s/match' % self .ratingKey
508+ if auto :
509+ searchResult = self .matches ()[0 ]
510+ elif not searchResult :
511+ raise NotFound ('fixMatch() requires either auto=True or '
512+ 'searchResult=:class:`~plexapi.media.SearchResult`.' )
513+
514+ params = {'guid' : searchResult .guid ,
515+ 'name' : searchResult .name }
516+
517+ data = key + '?' + urlencode (params )
518+ self ._server .query (data , method = self ._server ._session .put )
519+
436520 # The photo tag cant be built atm. TODO
437521 # def arts(self):
438522 # part = '%s/arts' % self.key
0 commit comments