Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images issues #127

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
14 changes: 13 additions & 1 deletion src/scraper/apiModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
})

/**
Expand Down
63 changes: 33 additions & 30 deletions src/scraper/helpers/MovieHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,29 @@ export default class MovieHelper extends AbstractHelper {
* from.
* @returns {Object} - Object with banner, fanart and poster images.
*/
_getTmdbImages(tmdbId: string): Promise<Object | Error> {
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.
Expand Down Expand Up @@ -206,12 +206,10 @@ export default class MovieHelper extends AbstractHelper {
* from.
* @returns {Promise<Object>} - Object with banner, fanart and poster images.
*/
getImages({tmdbId, imdbId}: Object): Promise<Object> {
return this._getTmdbImages(imdbId)
.catch(() => this._getOmdbImages(tmdbId))
.catch(() => this._getFanartImages(tmdbId))
.catch(() => AbstractHelper.DefaultImages)
}
getImages({imdbId, tmdbId}: Object): Promise<Object> {
return this._getTmdbImages(tmdbId)
.catch(() => AbstractHelper.DefaultImages)
}

/**
* Get info from Trakt and make a new movie object.
Expand All @@ -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,
Expand All @@ -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,
Expand Down