Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rating): added IMDB Radarr proxy (#3496)
* feat(rating): added imdb radarr proxy Signed-off-by: marcofaggian <m@marcofaggian.com> * refactor(rating/imdb): rm export unused interfaces Signed-off-by: marcofaggian <m@marcofaggian.com> * docs(rating/imdb): rt to imdb Signed-off-by: marcofaggian <m@marcofaggian.com> * refactor(rating/imdb): specified error message Signed-off-by: marcofaggian <m@marcofaggian.com> * refactor(rating/imdb): rm line break Signed-off-by: marcofaggian <m@marcofaggian.com> * refactor(rating): conform to types patter Signed-off-by: marcofaggian <m@marcofaggian.com> * chore(rating/imdb): added line to translation file Signed-off-by: marcofaggian <m@marcofaggian.com> * feat(rating/imdb): ratings to ratingscombined Signed-off-by: marcofaggian <m@marcofaggian.com> * fix(rating/imdb): reinstating ratings route Signed-off-by: marcofaggian <m@marcofaggian.com> * docs(ratings): openapi ratings Signed-off-by: marcofaggian <m@marcofaggian.com> * chore(ratings): undo openapi ratings apex Signed-off-by: marcofaggian <m@marcofaggian.com> --------- Signed-off-by: marcofaggian <m@marcofaggian.com>
- Loading branch information
1 parent
83b008c
commit b4191f9
Showing
10 changed files
with
384 additions
and
39 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
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,195 @@ | ||
import ExternalAPI from '@server/api/externalapi'; | ||
import cacheManager from '@server/lib/cache'; | ||
|
||
type IMDBRadarrProxyResponse = IMDBMovie[]; | ||
|
||
interface IMDBMovie { | ||
ImdbId: string; | ||
Overview: string; | ||
Title: string; | ||
OriginalTitle: string; | ||
TitleSlug: string; | ||
Ratings: Rating[]; | ||
MovieRatings: MovieRatings; | ||
Runtime: number; | ||
Images: Image[]; | ||
Genres: string[]; | ||
Popularity: number; | ||
Premier: string; | ||
InCinema: string; | ||
PhysicalRelease: any; | ||
DigitalRelease: string; | ||
Year: number; | ||
AlternativeTitles: AlternativeTitle[]; | ||
Translations: Translation[]; | ||
Recommendations: Recommendation[]; | ||
Credits: Credits; | ||
Studio: string; | ||
YoutubeTrailerId: string; | ||
Certifications: Certification[]; | ||
Status: any; | ||
Collection: Collection; | ||
OriginalLanguage: string; | ||
Homepage: string; | ||
TmdbId: number; | ||
} | ||
|
||
interface Rating { | ||
Count: number; | ||
Value: number; | ||
Origin: string; | ||
Type: string; | ||
} | ||
|
||
interface MovieRatings { | ||
Tmdb: Tmdb; | ||
Imdb: Imdb; | ||
Metacritic: Metacritic; | ||
RottenTomatoes: RottenTomatoes; | ||
} | ||
|
||
interface Tmdb { | ||
Count: number; | ||
Value: number; | ||
Type: string; | ||
} | ||
|
||
interface Imdb { | ||
Count: number; | ||
Value: number; | ||
Type: string; | ||
} | ||
|
||
interface Metacritic { | ||
Count: number; | ||
Value: number; | ||
Type: string; | ||
} | ||
|
||
interface RottenTomatoes { | ||
Count: number; | ||
Value: number; | ||
Type: string; | ||
} | ||
|
||
interface Image { | ||
CoverType: string; | ||
Url: string; | ||
} | ||
|
||
interface AlternativeTitle { | ||
Title: string; | ||
Type: string; | ||
Language: string; | ||
} | ||
|
||
interface Translation { | ||
Title: string; | ||
Overview: string; | ||
Language: string; | ||
} | ||
|
||
interface Recommendation { | ||
TmdbId: number; | ||
Title: string; | ||
} | ||
|
||
interface Credits { | ||
Cast: Cast[]; | ||
Crew: Crew[]; | ||
} | ||
|
||
interface Cast { | ||
Name: string; | ||
Order: number; | ||
Character: string; | ||
TmdbId: number; | ||
CreditId: string; | ||
Images: Image2[]; | ||
} | ||
|
||
interface Image2 { | ||
CoverType: string; | ||
Url: string; | ||
} | ||
|
||
interface Crew { | ||
Name: string; | ||
Job: string; | ||
Department: string; | ||
TmdbId: number; | ||
CreditId: string; | ||
Images: Image3[]; | ||
} | ||
|
||
interface Image3 { | ||
CoverType: string; | ||
Url: string; | ||
} | ||
|
||
interface Certification { | ||
Country: string; | ||
Certification: string; | ||
} | ||
|
||
interface Collection { | ||
Name: string; | ||
Images: any; | ||
Overview: any; | ||
Translations: any; | ||
Parts: any; | ||
TmdbId: number; | ||
} | ||
|
||
export interface IMDBRating { | ||
title: string; | ||
url: string; | ||
criticsScore: number; | ||
} | ||
|
||
/** | ||
* This is a best-effort API. The IMDB API is technically | ||
* private and getting access costs money/requires approval. | ||
* | ||
* Radarr hosts a public proxy that's in use by all Radarr instances. | ||
*/ | ||
class IMDBRadarrProxy extends ExternalAPI { | ||
constructor() { | ||
super('https://api.radarr.video/v1', { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
nodeCache: cacheManager.getCache('imdb').data, | ||
}); | ||
} | ||
|
||
/** | ||
* Ask the Radarr IMDB Proxy for the movie | ||
* | ||
* @param IMDBid Id of IMDB movie | ||
*/ | ||
public async getMovieRatings(IMDBid: string): Promise<IMDBRating | null> { | ||
try { | ||
const data = await this.get<IMDBRadarrProxyResponse>( | ||
`/movie/imdb/${IMDBid}` | ||
); | ||
|
||
if (!data?.length || data[0].ImdbId !== IMDBid) { | ||
return null; | ||
} | ||
|
||
return { | ||
title: data[0].Title, | ||
url: `https://www.imdb.com/title/${data[0].ImdbId}`, | ||
criticsScore: data[0].MovieRatings.Imdb.Value, | ||
}; | ||
} catch (e) { | ||
throw new Error( | ||
`[IMDB RADARR PROXY API] Failed to retrieve movie ratings: ${e.message}` | ||
); | ||
} | ||
} | ||
} | ||
|
||
export default IMDBRadarrProxy; |
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
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,7 @@ | ||
import { type IMDBRating } from '@server/api/rating/imdbRadarrProxy'; | ||
import { type RTRating } from '@server/api/rating/rottentomatoes'; | ||
|
||
export interface RatingResponse { | ||
rt?: RTRating; | ||
imdb?: IMDBRating; | ||
} |
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
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
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
Oops, something went wrong.