-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fanart): Implemented Fanart service
- Loading branch information
Showing
5 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.