From 4aa74319e0adcc19041239e57a00bc40fb127826 Mon Sep 17 00:00:00 2001 From: sct Date: Sun, 20 Sep 2020 14:42:13 +0900 Subject: [PATCH] feat(api): add external ids to movie/tv response --- server/api/themoviedb.ts | 17 +++++++++++++++-- server/entity/MediaRequest.ts | 7 +++++++ server/models/Movie.ts | 4 ++++ server/models/Tv.ts | 4 ++++ server/models/common.ts | 28 +++++++++++++++++++++++++++- server/overseerr-api.yml | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 3 deletions(-) diff --git a/server/api/themoviedb.ts b/server/api/themoviedb.ts index f4fec0726..123108d7b 100644 --- a/server/api/themoviedb.ts +++ b/server/api/themoviedb.ts @@ -121,6 +121,17 @@ export interface TmdbCreditCrew { department: string; } +export interface TmdbExternalIds { + imdb_id?: string; + freebase_mid?: string; + freebase_id?: string; + tvdb_id?: number; + tvrage_id?: string; + facebook_id?: string; + instagram_id?: string; + twitter_id?: string; +} + export interface TmdbMovieDetails { id: number; imdb_id?: string; @@ -164,6 +175,7 @@ export interface TmdbMovieDetails { cast: TmdbCreditCast[]; crew: TmdbCreditCrew[]; }; + external_ids: TmdbExternalIds; } export interface TmdbTvEpisodeDetails { @@ -242,6 +254,7 @@ export interface TmdbTvDetails { cast: TmdbCreditCast[]; crew: TmdbCreditCrew[]; }; + external_ids: TmdbExternalIds; } class TheMovieDb { @@ -289,7 +302,7 @@ class TheMovieDb { const response = await this.axios.get( `/movie/${movieId}`, { - params: { language, append_to_response: 'credits' }, + params: { language, append_to_response: 'credits,external_ids' }, } ); @@ -308,7 +321,7 @@ class TheMovieDb { }): Promise => { try { const response = await this.axios.get(`/tv/${tvId}`, { - params: { language, append_to_response: 'credits' }, + params: { language, append_to_response: 'credits,external_ids' }, }); return response.data; diff --git a/server/entity/MediaRequest.ts b/server/entity/MediaRequest.ts index fba077b1f..952b5cb97 100644 --- a/server/entity/MediaRequest.ts +++ b/server/entity/MediaRequest.ts @@ -73,6 +73,13 @@ export class MediaRequest { @Index() public mediaId: number; + @Column({ unique: true, nullable: true }) + @Index() + public tvdbId: number; + + @Column({ nullable: true }) + public seasons?: string; + @Column() public mediaType: 'movie' | 'tv'; diff --git a/server/models/Movie.ts b/server/models/Movie.ts index 912fb70e5..329e7ae05 100644 --- a/server/models/Movie.ts +++ b/server/models/Movie.ts @@ -7,6 +7,8 @@ import { Crew, mapCast, mapCrew, + ExternalIds, + mapExternalIds, } from './common'; export interface MovieDetails { @@ -45,6 +47,7 @@ export interface MovieDetails { crew: Crew[]; }; request?: MediaRequest; + externalIds: ExternalIds; } export const mapMovieDetails = ( @@ -84,5 +87,6 @@ export const mapMovieDetails = ( cast: movie.credits.cast.map(mapCast), crew: movie.credits.crew.map(mapCrew), }, + externalIds: mapExternalIds(movie.external_ids), request, }); diff --git a/server/models/Tv.ts b/server/models/Tv.ts index b4078858a..246b56b2e 100644 --- a/server/models/Tv.ts +++ b/server/models/Tv.ts @@ -5,6 +5,8 @@ import { Crew, mapCast, mapCrew, + ExternalIds, + mapExternalIds, } from './common'; import { MediaRequest } from '../entity/MediaRequest'; import { @@ -75,6 +77,7 @@ export interface TvDetails { cast: Cast[]; crew: Crew[]; }; + externalIds: ExternalIds; request?: MediaRequest; } @@ -155,5 +158,6 @@ export const mapTvDetails = ( cast: show.credits.cast.map(mapCast), crew: show.credits.crew.map(mapCrew), }, + externalIds: mapExternalIds(show.external_ids), request, }); diff --git a/server/models/common.ts b/server/models/common.ts index 0e4ed7e07..696f7df23 100644 --- a/server/models/common.ts +++ b/server/models/common.ts @@ -1,4 +1,8 @@ -import { TmdbCreditCast, TmdbCreditCrew } from '../api/themoviedb'; +import { + TmdbCreditCast, + TmdbCreditCrew, + TmdbExternalIds, +} from '../api/themoviedb'; export interface ProductionCompany { id: number; @@ -33,6 +37,17 @@ export interface Crew { profilePath?: string; } +export interface ExternalIds { + imdbId?: string; + freebaseMid?: string; + freebaseId?: string; + tvdbId?: number; + tvrageId?: string; + facebookId?: string; + instagramId?: string; + twitterId?: string; +} + export const mapCast = (person: TmdbCreditCast): Cast => ({ castId: person.cast_id, character: person.character, @@ -53,3 +68,14 @@ export const mapCrew = (person: TmdbCreditCrew): Crew => ({ gender: person.gender, profilePath: person.profile_path, }); + +export const mapExternalIds = (eids: TmdbExternalIds): ExternalIds => ({ + facebookId: eids.facebook_id, + freebaseId: eids.freebase_id, + freebaseMid: eids.freebase_mid, + imdbId: eids.imdb_id, + instagramId: eids.instagram_id, + tvdbId: eids.tvdb_id, + tvrageId: eids.tvrage_id, + twitterId: eids.twitter_id, +}); diff --git a/server/overseerr-api.yml b/server/overseerr-api.yml index 7c6c44180..58997b00d 100644 --- a/server/overseerr-api.yml +++ b/server/overseerr-api.yml @@ -433,6 +433,8 @@ components: type: array items: $ref: '#/components/schemas/Crew' + externalIds: + $ref: '#/components/schemas/ExternalIds' request: $ref: '#/components/schemas/MediaRequest' Episode: @@ -573,6 +575,8 @@ components: type: array items: $ref: '#/components/schemas/Crew' + externalIds: + $ref: '#/components/schemas/ExternalIds' request: $ref: '#/components/schemas/MediaRequest' MediaRequest: @@ -657,6 +661,25 @@ components: type: string profilePath: type: string + ExternalIds: + type: object + properties: + facebookId: + type: string + freebaseId: + type: string + freebaseMid: + type: string + imdbId: + type: string + instagramId: + type: string + tvdbId: + type: string + tvrageId: + type: string + twitterId: + type: string securitySchemes: cookieAuth: @@ -1219,6 +1242,16 @@ paths: mediaId: type: number example: 123 + tvdbId: + type: number + example: 123 + seasons: + type: array + items: + type: number + required: + - mediaType + - mediaId responses: '201': description: Succesfully created the request