Skip to content

Commit 743fc73

Browse files
committed
feat(fanart): Added getShowImages
1 parent 289edf1 commit 743fc73

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

libs/services/fanart/src/fanart.service.ts

+44-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable, Logger } from '@nestjs/common'
22
import * as Fanart from 'fanart.tv-api'
3-
import { Images, Movie } from '@pct-org/mongo-models'
3+
import { Images, ImagesSizes, Movie, Show } from '@pct-org/mongo-models'
44

55
@Injectable()
66
export class FanartService {
@@ -42,23 +42,54 @@ export class FanartService {
4242

4343
return {
4444
backdrop: backdrop
45-
? {
46-
full: backdrop.url,
47-
high: backdrop.url,
48-
medium: backdrop.url,
49-
thumb: backdrop.url
50-
}
45+
? this.formatImage(backdrop)
5146
: item.images.backdrop,
5247

5348
poster: poster
54-
? {
55-
full: poster.url,
56-
high: poster.url,
57-
medium: poster.url,
58-
thumb: poster.url
59-
}
49+
? this.formatImage(poster)
6050
: item.images.poster
6151
}
6252
}
6353

54+
public async getShowImages(item: Show): Promise<Images> {
55+
let poster = null
56+
let backdrop = null
57+
58+
try {
59+
const images = await this.fanart.getShowImages(item.tvdbId)
60+
61+
backdrop = !item.images.backdrop.full && images.showbackground
62+
? images.showbackground.shift()
63+
: !item.images.backdrop && images.clearart
64+
? images.clearart.shift()
65+
: null
66+
67+
poster = !item.images.poster.full && images.tvposter
68+
? images.tvposter.shift()
69+
: null
70+
71+
} catch (err) {
72+
this.logger.error(`Error happened getting images for '${item.slug}'`, err)
73+
}
74+
75+
return {
76+
backdrop: backdrop
77+
? this.formatImage(backdrop)
78+
: item.images.backdrop,
79+
80+
poster: poster
81+
? this.formatImage(poster)
82+
: item.images.poster
83+
}
84+
}
85+
86+
private formatImage(image: { url: string }): ImagesSizes {
87+
return {
88+
full: image.url,
89+
high: image.url,
90+
medium: image.url,
91+
thumb: image.url
92+
}
93+
}
94+
6495
}

0 commit comments

Comments
 (0)