diff --git a/seasoned_api/src/tmdb/convertTmdbToSeasoned.js b/seasoned_api/src/tmdb/convertTmdbToSeasoned.js index 9fcbd4c..f30db22 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; diff --git a/seasoned_api/src/tmdb/tmdb.js b/seasoned_api/src/tmdb/tmdb.js index 84ff91b..269376b 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.type === 'movie' || element.type === 'tv'); + }).map((element) => convertTmdbToSeasoned(element, type)); return [mappedResults, response.page, response.total_pages, response.total_results]; }) .catch((error) => { throw new Error(error); });