Merge pull request #472 from pkkid/matching_fix

matching_fix
This commit is contained in:
Steffen Fredriksen 2020-05-10 14:30:59 +02:00 committed by GitHub
commit 226737807e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 127 additions and 18 deletions

View file

@ -519,7 +519,11 @@ class PlexPartialObject(PlexObject):
key = '/library/metadata/%s/matches' % self.ratingKey
params = {'manual': 1}
if any([agent, title, year, language]):
if agent and not any([title, year, language]):
params['language'] = self.section().language
params['agent'] = utils.getAgentIdentifier(self.section(), agent)
else:
if any(x is not None for x in [agent, title, year, language]):
if title is None:
params['title'] = self.title
else:
@ -539,9 +543,9 @@ class PlexPartialObject(PlexObject):
key = key + '?' + urlencode(params)
data = self._server.query(key, method=self._server._session.get)
return self.findItems(data)
return self.findItems(data, initpath=key)
def fixMatch(self, searchResult=None, auto=False):
def fixMatch(self, searchResult=None, auto=False, agent=None):
""" Use match result to update show metadata.
Parameters:
@ -549,10 +553,15 @@ class PlexPartialObject(PlexObject):
False allows user to provide the match
searchResult (:class:`~plexapi.media.SearchResult`): Search result from
~plexapi.base.matches()
agent (str): Agent name to be used (imdb, thetvdb, themoviedb, etc.)
"""
key = '/library/metadata/%s/match' % self.ratingKey
if auto:
searchResult = self.matches()[0]
autoMatch = self.matches(agent=agent)
if autoMatch:
searchResult = autoMatch[0]
else:
raise NotFound('No matches found using this agent: (%s:%s)' % (agent, autoMatch))
elif not searchResult:
raise NotFound('fixMatch() requires either auto=True or '
'searchResult=:class:`~plexapi.media.SearchResult`.')

View file

@ -5,6 +5,7 @@ from time import sleep
import pytest
from plexapi.exceptions import BadRequest, NotFound
from plexapi.compat import quote_plus
from . import conftest as utils
@ -349,6 +350,105 @@ def test_video_Movie_history(movie):
movie.markUnwatched()
def test_video_Movie_match(movies):
sectionAgent = movies.agent
sectionAgents = [agent.identifier for agent in movies.agents() if agent.shortIdentifier != 'none']
sectionAgents.remove(sectionAgent)
altAgent = sectionAgents[0]
movie = movies.all()[0]
title = movie.title
year = str(movie.year)
titleUrlEncode = quote_plus(title)
def parse_params(key):
params = key.split('?', 1)[1]
params = params.split("&")
return {x.split("=")[0]: x.split("=")[1] for x in params}
results = movie.matches(title="", year="")
if results:
initpath = results[0]._initpath
assert initpath.startswith(movie.key)
params = initpath.split(movie.key)[1]
parsedParams = parse_params(params)
assert parsedParams.get('manual') == '1'
assert parsedParams.get('title') == ""
assert parsedParams.get('year') == ""
assert parsedParams.get('agent') == sectionAgent
else:
assert len(results) == 0
results = movie.matches(title=title, year="", agent=sectionAgent)
if results:
initpath = results[0]._initpath
assert initpath.startswith(movie.key)
params = initpath.split(movie.key)[1]
parsedParams = parse_params(params)
assert parsedParams.get('manual') == '1'
assert parsedParams.get('title') == titleUrlEncode
assert parsedParams.get('year') == ""
assert parsedParams.get('agent') == sectionAgent
else:
assert len(results) == 0
results = movie.matches(title=title, agent=sectionAgent)
if results:
initpath = results[0]._initpath
assert initpath.startswith(movie.key)
params = initpath.split(movie.key)[1]
parsedParams = parse_params(params)
assert parsedParams.get('manual') == '1'
assert parsedParams.get('title') == titleUrlEncode
assert parsedParams.get('year') == year
assert parsedParams.get('agent') == sectionAgent
else:
assert len(results) == 0
results = movie.matches(title="", year="")
if results:
initpath = results[0]._initpath
assert initpath.startswith(movie.key)
params = initpath.split(movie.key)[1]
parsedParams = parse_params(params)
assert parsedParams.get('manual') == '1'
assert parsedParams.get('agent') == sectionAgent
else:
assert len(results) == 0
results = movie.matches(title="", year="", agent=altAgent)
if results:
initpath = results[0]._initpath
assert initpath.startswith(movie.key)
params = initpath.split(movie.key)[1]
parsedParams = parse_params(params)
assert parsedParams.get('manual') == '1'
assert parsedParams.get('agent') == altAgent
else:
assert len(results) == 0
results = movie.matches(agent=altAgent)
if results:
initpath = results[0]._initpath
assert initpath.startswith(movie.key)
params = initpath.split(movie.key)[1]
parsedParams = parse_params(params)
assert parsedParams.get('manual') == '1'
assert parsedParams.get('agent') == altAgent
else:
assert len(results) == 0
results = movie.matches()
if results:
initpath = results[0]._initpath
assert initpath.startswith(movie.key)
params = initpath.split(movie.key)[1]
parsedParams = parse_params(params)
assert parsedParams.get('manual') == '1'
else:
assert len(results) == 0
def test_video_Show(show):
assert show.title == "Game of Thrones"