From 7db62ab824eefc42e6db16e42d52f4266b136f82 Mon Sep 17 00:00:00 2001 From: sct Date: Mon, 18 Jan 2021 02:47:12 +0000 Subject: [PATCH] fix(api): improve rottentomatoes rating matching for movies fixes #494 --- server/api/rottentomatoes.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/server/api/rottentomatoes.ts b/server/api/rottentomatoes.ts index 7c1c5985b..cc3a562a6 100644 --- a/server/api/rottentomatoes.ts +++ b/server/api/rottentomatoes.ts @@ -92,7 +92,27 @@ class RottenTomatoes { } ); - const movie = response.data.movies.find((movie) => movie.year === year); + // First, attempt to match exact name and year + let movie = response.data.movies.find( + (movie) => movie.year === year && movie.title === name + ); + + // If we don't find a movie, try to match partial name and year + if (!movie) { + movie = response.data.movies.find( + (movie) => movie.year === year && movie.title.includes(name) + ); + } + + // If we still dont find a movie, try to match just on year + if (!movie) { + movie = response.data.movies.find((movie) => movie.year === year); + } + + // One last try, try exact name match only + if (!movie) { + movie = response.data.movies.find((movie) => movie.title === name); + } if (!movie) { return null;