Skip to content

Commit

Permalink
feat(fanart): Implemented Fanart service
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 15, 2020
1 parent 74e448d commit 6f544d5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 11 deletions.
15 changes: 15 additions & 0 deletions libs/services/fanart/src/fanart.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module, Global } from '@nestjs/common'

import { FanartService } from './fanart.service'

@Global()
@Module({
providers: [
FanartService
],
exports: [
FanartService
]
})
export class FanartModule {
}
64 changes: 64 additions & 0 deletions libs/services/fanart/src/fanart.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Injectable, Logger } from '@nestjs/common'
import * as Fanart from 'fanart.tv-api'
import { Images, Movie } from '@pct-org/mongo-models'

@Injectable()
export class FanartService {

private readonly fanart

private readonly logger = new Logger('Fanart')

constructor() {
const fanartkey = process.env.FANART_KEY

if (fanartkey) {
this.fanart = new Fanart({
apiKey: fanartkey
})
}
}

public async getMovieImages(item: Movie): Promise<Images> {
let poster = null
let backdrop = null

try {
const images = await this.fanart.getMovieImages(item.tmdbId)

backdrop = !item.images.backdrop && images.moviebackground
? images.moviebackground.shift()
: !item.images.backdrop && images.hdmovieclearart
? images.hdmovieclearart.shift()
: null

poster = !item.images.poster && images.movieposter
? images.movieposter.shift()
: null

} catch (err) {
this.logger.error(`Error happened getting images for '${item.slug}'`, err)
}

return {
backdrop: backdrop
? {
full: backdrop.url,
high: backdrop.url,
medium: backdrop.url,
thumb: backdrop.url
}
: item.images.backdrop,

poster: poster
? {
full: poster.url,
high: poster.url,
medium: poster.url,
thumb: poster.url
}
: item.images.poster
}
}

}
3 changes: 2 additions & 1 deletion libs/services/fanart/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './lib/services-fanart';
export * from './fanart.module'
export * from './fanart.service'
7 changes: 0 additions & 7 deletions libs/services/fanart/src/lib/services-fanart.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions libs/services/fanart/src/lib/services-fanart.ts

This file was deleted.

0 comments on commit 6f544d5

Please sign in to comment.