From d6ac7e55e91eb5fe603e3a7b26978a71569b851d Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 15 Aug 2022 23:38:35 +0200 Subject: [PATCH] Better matching when getting matchin plex title & year --- seasoned_api/src/plex/plex.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/seasoned_api/src/plex/plex.js b/seasoned_api/src/plex/plex.js index 1568596..9a1af74 100644 --- a/seasoned_api/src/plex/plex.js +++ b/seasoned_api/src/plex/plex.js @@ -127,15 +127,12 @@ class Plex { findPlexItemByTitleAndYear(title, year) { const query = { title, year }; - return this.search(query.title).then(plexSearchResults => { - const matchesInPlex = plexSearchResults.map(plex => + return this.search(title).then(plexResults => { + const matchesInPlex = plexResults.map(plex => this.matchTmdbAndPlexMedia(plex, query) ); - - if (matchesInPlex.includes(true) === false) return false; - - const firstMatchIndex = matchesInPlex.indexOf(true); - return plexSearchResults[firstMatchIndex][0]; + const matchesIndex = matchesInPlex.findIndex(el => el === true); + return matchesInPlex != -1 ? plexResults[matchesIndex] : null; }); }