diff --git a/package.json b/package.json index d4ee0b4..d20ae67 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "pop-api-scraper": "^0.1.2", "tmdbapi": "^1.0.2", "trakt.tv": "^6.0.2", + "trakt.tv-images": "^5.2.0", "webtorrent-health": "^1.1.1", "yts-api-pt": "^2.0.0" }, diff --git a/src/scraper/apiModules.js b/src/scraper/apiModules.js index a3e574d..67b404e 100644 --- a/src/scraper/apiModules.js +++ b/src/scraper/apiModules.js @@ -119,7 +119,19 @@ const tmdb = new Tmdb({ * @see https://github.com/vankasteelj/trakt.tv */ const trakt = new Trakt({ - client_id: process.env.TRAKT_KEY + client_id: process.env.TRAKT_KEY, + plugins: { + images: require('trakt.tv-images') +}, +options: { + images: { + smallerImages: true, + fanartApiKey: process.env.FANART_KEY, + tvdbApiKey: process.env.TVDB_KEY, + tmdbApiKey: process.env.TMDB_KEY + } + +} }) /** diff --git a/src/scraper/helpers/MovieHelper.js b/src/scraper/helpers/MovieHelper.js index 770e077..bceaced 100644 --- a/src/scraper/helpers/MovieHelper.js +++ b/src/scraper/helpers/MovieHelper.js @@ -127,29 +127,29 @@ export default class MovieHelper extends AbstractHelper { * from. * @returns {Object} - Object with banner, fanart and poster images. */ - _getTmdbImages(tmdbId: string): Promise { - return tmdb.movie.images({ - movie_id: tmdbId - }).then(i => { - const baseUrl = 'http://image.tmdb.org/t/p/w500' + _getTmdbImages(tmdbId: number): Object { + return tmdb.tv.images({ + tv_id: tmdbId + }).then(i => { + const baseUrl = 'http://image.tmdb.org/t/p/w500' - const tmdbPoster = i.posters.filter( - poster => poster.iso_639_1 === 'en' || poster.iso_639_1 === null - )[0].file_path - const tmdbBackdrop = i.backdrops.filter( - backdrop => backdrop.iso_639_1 === 'en' || backdrop.iso_639_1 === null - )[0].file_path + const tmdbPoster = i.posters.filter( + poster => poster.iso_639_1 === 'en' || poster.iso_639_1 === null + )[0].file_path + const tmdbBackdrop = i.backdrops.filter( + backdrop => backdrop.iso_639_1 === 'en' || backdrop.iso_639_1 === null + )[0].file_path - const { Holder } = AbstractHelper - const images = { - banner: tmdbPoster ? `${baseUrl}${tmdbPoster}` : Holder, - fanart: tmdbBackdrop ? `${baseUrl}${tmdbBackdrop}` : Holder, - poster: tmdbPoster ? `${baseUrl}${tmdbPoster}` : Holder - } + const { Holder } = AbstractHelper + const images = { + banner: tmdbPoster ? `${baseUrl}${tmdbPoster}` : Holder, + fanart: tmdbBackdrop ? `${baseUrl}${tmdbBackdrop}` : Holder, + poster: tmdbPoster ? `${baseUrl}${tmdbPoster}` : Holder + } - return this.checkImages(images) - }) - } + return this.checkImages(images) + }) + } /** * Get movie images from OMDB. @@ -206,12 +206,10 @@ export default class MovieHelper extends AbstractHelper { * from. * @returns {Promise} - Object with banner, fanart and poster images. */ - getImages({tmdbId, imdbId}: Object): Promise { - return this._getTmdbImages(imdbId) - .catch(() => this._getOmdbImages(tmdbId)) - .catch(() => this._getFanartImages(tmdbId)) - .catch(() => AbstractHelper.DefaultImages) - } + getImages({imdbId, tmdbId}: Object): Promise { + return this._getTmdbImages(tmdbId) + .catch(() => AbstractHelper.DefaultImages) + } /** * Get info from Trakt and make a new movie object. @@ -231,10 +229,11 @@ export default class MovieHelper extends AbstractHelper { if (traktMovie && traktMovie.ids.imdb && traktMovie.ids.tmdb) { const { imdb, slug, tmdb } = traktMovie.ids - const images = this.getImages({ - imdbId: imdb, - tmdbId: tmdb + const img = await trakt.images.get({ + tmdb: traktMovie.ids.imdb + imdb: traktMovie.ids.imdb }) + console.log(img); return { imdb_id: imdb, @@ -248,7 +247,11 @@ export default class MovieHelper extends AbstractHelper { watching: traktWatchers ? traktWatchers.length : 0, percentage: Math.round(traktMovie.rating * 10) }, - images, + images: { + banner: img.fanart, + fanart: img.background, + poster: img.poster + }, genres: traktMovie.genres ? traktMovie.genres : ['unknown'], language: traktMovie.language, released: new Date(traktMovie.released).getTime() / 1000.0,