Skip to content

Commit

Permalink
feat(api): add external ids to movie/tv response
Browse files Browse the repository at this point in the history
  • Loading branch information
sct committed Sep 20, 2020
1 parent 02cbb5b commit 4aa7431
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
17 changes: 15 additions & 2 deletions server/api/themoviedb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,6 +175,7 @@ export interface TmdbMovieDetails {
cast: TmdbCreditCast[];
crew: TmdbCreditCrew[];
};
external_ids: TmdbExternalIds;
}

export interface TmdbTvEpisodeDetails {
Expand Down Expand Up @@ -242,6 +254,7 @@ export interface TmdbTvDetails {
cast: TmdbCreditCast[];
crew: TmdbCreditCrew[];
};
external_ids: TmdbExternalIds;
}

class TheMovieDb {
Expand Down Expand Up @@ -289,7 +302,7 @@ class TheMovieDb {
const response = await this.axios.get<TmdbMovieDetails>(
`/movie/${movieId}`,
{
params: { language, append_to_response: 'credits' },
params: { language, append_to_response: 'credits,external_ids' },
}
);

Expand All @@ -308,7 +321,7 @@ class TheMovieDb {
}): Promise<TmdbTvDetails> => {
try {
const response = await this.axios.get<TmdbTvDetails>(`/tv/${tvId}`, {
params: { language, append_to_response: 'credits' },
params: { language, append_to_response: 'credits,external_ids' },
});

return response.data;
Expand Down
7 changes: 7 additions & 0 deletions server/entity/MediaRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 4 additions & 0 deletions server/models/Movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
Crew,
mapCast,
mapCrew,
ExternalIds,
mapExternalIds,
} from './common';

export interface MovieDetails {
Expand Down Expand Up @@ -45,6 +47,7 @@ export interface MovieDetails {
crew: Crew[];
};
request?: MediaRequest;
externalIds: ExternalIds;
}

export const mapMovieDetails = (
Expand Down Expand Up @@ -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,
});
4 changes: 4 additions & 0 deletions server/models/Tv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
Crew,
mapCast,
mapCrew,
ExternalIds,
mapExternalIds,
} from './common';
import { MediaRequest } from '../entity/MediaRequest';
import {
Expand Down Expand Up @@ -75,6 +77,7 @@ export interface TvDetails {
cast: Cast[];
crew: Crew[];
};
externalIds: ExternalIds;
request?: MediaRequest;
}

Expand Down Expand Up @@ -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,
});
28 changes: 27 additions & 1 deletion server/models/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { TmdbCreditCast, TmdbCreditCrew } from '../api/themoviedb';
import {
TmdbCreditCast,
TmdbCreditCrew,
TmdbExternalIds,
} from '../api/themoviedb';

export interface ProductionCompany {
id: number;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
});
33 changes: 33 additions & 0 deletions server/overseerr-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ components:
type: array
items:
$ref: '#/components/schemas/Crew'
externalIds:
$ref: '#/components/schemas/ExternalIds'
request:
$ref: '#/components/schemas/MediaRequest'
Episode:
Expand Down Expand Up @@ -573,6 +575,8 @@ components:
type: array
items:
$ref: '#/components/schemas/Crew'
externalIds:
$ref: '#/components/schemas/ExternalIds'
request:
$ref: '#/components/schemas/MediaRequest'
MediaRequest:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4aa7431

Please sign in to comment.