diff --git a/seasoned_api/src/plex/plexRepository.js b/seasoned_api/src/plex/plexRepository.js index bde5c01..a51f331 100644 --- a/seasoned_api/src/plex/plexRepository.js +++ b/seasoned_api/src/plex/plexRepository.js @@ -23,7 +23,7 @@ class PlexRepository { .then(([mappedResults, resultCount]) => ({ results: mappedResults, total_results: resultCount })); } - static compareTmdbToPlex(tmdb, plexResult) { + compareTmdbToPlex(tmdb, plexResult) { return Promise.resolve() .then(() => { plexResult.results.map((plexItem) => { @@ -34,7 +34,7 @@ class PlexRepository { }); } - static mapResults(response) { + mapResults(response) { return Promise.resolve() .then(() => { if (!response.MediaContainer.hasOwnProperty('Metadata')) return [[], 0]; diff --git a/seasoned_api/src/tmdb/convertTmdbToSeasoned.js b/seasoned_api/src/tmdb/convertTmdbToSeasoned.js index 9fcbd4c..05502b9 100644 --- a/seasoned_api/src/tmdb/convertTmdbToSeasoned.js +++ b/seasoned_api/src/tmdb/convertTmdbToSeasoned.js @@ -9,10 +9,15 @@ function translateGenre(tmdbGenres) { return tmdbGenres.map(genre => genre.name); } +function convertType(tmdbType) { + if (tmdbType === 'tv') return 'show'; + return undefined; +} + function convertTmdbToSeasoned(tmdb, manualType = undefined) { const title = tmdb.title || tmdb.name; const year = translateYear(tmdb.release_date || tmdb.first_air_date); - const type = tmdb.media_type || manualType; + const type = manualType || convertType(tmdb.media_type) || 'movie'; const id = tmdb.id; const summary = tmdb.overview; @@ -29,7 +34,7 @@ function convertTmdbToSeasoned(tmdb, manualType = undefined) { const seasoned = new TMDB( title, year, type, id, summary, poster_path, background_path, - popularity, score, release_status, tagline, seasons, episodes, + popularity, score, release_status, tagline, seasons, episodes ); // seasoned.print() diff --git a/seasoned_api/src/tmdb/tmdb.js b/seasoned_api/src/tmdb/tmdb.js index 84ff91b..da86ec9 100644 --- a/seasoned_api/src/tmdb/tmdb.js +++ b/seasoned_api/src/tmdb/tmdb.js @@ -12,7 +12,6 @@ const TMDB_METHODS = { }; class TMDB { - constructor(cache, apiKey, tmdbLibrary) { this.cache = cache; this.tmdbLibrary = tmdbLibrary || moviedb(apiKey); @@ -63,7 +62,7 @@ class TMDB { .catch(() => this.tmdb(this.tmdbMethod('search', type), query)) .catch(() => { throw new Error('Could not search for movies/shows at tmdb.'); }) .then(response => this.cache.set(cacheKey, response)) - .then(response => this.mapResults(response, type)) + .then(response => this.mapResults(response)) .catch((error) => { throw new Error(error); }) .then(([mappedResults, pagenumber, totalpages, total_results]) => ({ results: mappedResults, page: pagenumber, total_results, total_pages: totalpages, @@ -107,7 +106,9 @@ class TMDB { mapResults(response, type) { return Promise.resolve() .then(() => { - const mappedResults = response.results.map(result => convertTmdbToSeasoned(result, type)); + const mappedResults = response.results.filter((element) => { + return (element.media_type === 'movie' || element.media_type === 'tv' || element.media_type === undefined); + }).map((element) => convertTmdbToSeasoned(element, type)); return [mappedResults, response.page, response.total_pages, response.total_results]; }) .catch((error) => { throw new Error(error); });