@@ -471,6 +471,90 @@ def setArt(self, art):
471471 """ Set :class:`~plexapi.media.Poster` to :class:`~plexapi.video.Video` """
472472 art .select ()
473473
474+ def unmatch (self ):
475+ """ Unmatches metadata match from object. """
476+ key = '/library/metadata/%s/unmatch' % self .ratingKey
477+ self ._server .query (key , method = self ._server ._session .put )
478+
479+ def matches (self , auto = False , agent = None , title = None , year = None , language = None ):
480+ """ Return list of (:class:`~plexapi.media.SearchResult) metadata matches.
481+
482+ Parameters:
483+ auto (bool): True searches for matches automatically
484+ False allows for user to provide additional parameters to search
485+ *Auto searching
486+ agent (str): Agent name to be used (imdb, thetvdb, themoviedb, etc.)
487+ title (str): Title of item to search for
488+ year (str): Year of item to search in
489+ language (str) : Language of item to search in
490+
491+ Examples:
492+ 1. video.matches()
493+ 2. video.matches(title="something", year=2020)
494+ 3. video.matches(title="something")
495+ 4. video.matches(year=2020)
496+ 5. video.matches(title="something", year="")
497+ 6. video.matches(title="", year=2020)
498+ 7. video.matches(title="", year="")
499+
500+ 1. The default behaviour in Plex Web = no params in plexapi
501+ 2. Both title and year specified by user
502+ 3. Year automatically filled in
503+ 4. Title automatically filled in
504+ 5. Explicitly searches for title with blank year
505+ 6. Explicitly searches for blank title with year
506+ 7. I don't know what the user is thinking... return the same result as 1
507+
508+ For 2 to 7, the agent and language is automatically filled in
509+ """
510+ key = '/library/metadata/%s/matches' % self .ratingKey
511+ params = {'manual' : 1 }
512+
513+ if any ([agent , title , year , language ]):
514+ if title is None :
515+ params ['title' ] = self .title
516+ else :
517+ params ['title' ] = title
518+
519+ if year is None :
520+ params ['year' ] = self .year
521+ else :
522+ params ['year' ] = year
523+
524+ params ['language' ] = language or self .section ().language
525+
526+ if agent is None :
527+ params ['agent' ] = self .section ().agent
528+ else :
529+ params ['agent' ] = utils .getAgentIdentifier (self .section (), agent )
530+
531+ key = key + '?' + urlencode (params )
532+ data = self ._server .query (key , method = self ._server ._session .get )
533+ return self .findItems (data )
534+
535+ def fixMatch (self , searchResult = None , auto = False ):
536+ """ Use match result to update show metadata.
537+
538+ Parameters:
539+ auto (bool): True uses first match from matches
540+ False allows user to provide the match
541+ *Auto matching
542+ searchResult (:class:`~plexapi.media.SearchResult): Search result from
543+ ~plexapi.base.matches()
544+ """
545+ key = '/library/metadata/%s/match' % self .ratingKey
546+ if auto :
547+ searchResult = self .matches ()[0 ]
548+ elif not searchResult :
549+ raise NotFound ('fixMatch() requires either auto=True or '
550+ 'searchResult=:class:`~plexapi.media.SearchResult`.' )
551+
552+ params = {'guid' : searchResult .guid ,
553+ 'name' : searchResult .name }
554+
555+ data = key + '?' + urlencode (params )
556+ self ._server .query (data , method = self ._server ._session .put )
557+
474558 # The photo tag cant be built atm. TODO
475559 # def arts(self):
476560 # part = '%s/arts' % self.key
0 commit comments