Handle exact match differently in the scanner

This commit is contained in:
Zoe Roux 2023-09-05 23:37:36 +02:00
parent 8a3a2fecf5
commit 3549f8b2d2

View File

@ -325,8 +325,8 @@ class TheMovieDatabase(Provider):
await self.get_absolute_order(show_id) await self.get_absolute_order(show_id)
if ( if (
absolute and absolute
(not season or not episode_nbr) and (not season or not episode_nbr)
and self.absolute_episode_cache[show_id] and self.absolute_episode_cache[show_id]
and self.absolute_episode_cache[show_id][absolute] and self.absolute_episode_cache[show_id][absolute]
): ):
@ -401,21 +401,34 @@ class TheMovieDatabase(Provider):
def get_best_result( def get_best_result(
self, search_results: List[Any], name: str, year: Optional[int] self, search_results: List[Any], name: str, year: Optional[int]
) -> Any: ) -> Any:
if year: results = search_results
# Find perfect match by year since sometime tmdb decides to discard the year parameter. # Find perfect match by year since sometime tmdb decides to discard the year parameter.
return next( if year:
( results = list(
x x
for x in search_results for x in search_results
if ( if ("first_air_date" in x and x["first_air_date"].startswith(str(year)))
"first_air_date" in x
and x["first_air_date"].startswith(str(year))
)
or ("release_date" in x and x["release_date"].startswith(str(year))) or ("release_date" in x and x["release_date"].startswith(str(year)))
),
search_results[0],
) )
return search_results[0] if not results:
results = search_results
# If there is a perfect match use it (and if there are multiple, use the most popular one)
res = sorted(
(
x
for x in results
if ("name" in x and x["name"] == name)
or ("title" in x and x["title"] == name)
),
key=lambda x: x["popularity"],
reverse=True,
)
if res:
results = res
return results[0]
async def get_absolute_order(self, show_id: str): async def get_absolute_order(self, show_id: str):
try: try: