Skip to content

Commit

Permalink
feat(tv): show cast for the entire show instead of only the last seas…
Browse files Browse the repository at this point in the history
…on (#778)

This uses TMDb's `aggregate_credits` instead of `credits` to get the show's cast for all seasons.

Fixes #775
  • Loading branch information
danshilm committed Jan 31, 2021
1 parent e2b8000 commit b239598
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
15 changes: 13 additions & 2 deletions server/api/themoviedb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export interface TmdbCreditCast {
profile_path?: string;
}

export interface TmdbAggregateCreditCast extends TmdbCreditCast {
roles: {
credit_id: string;
character: string;
episode_count: number;
}[];
}

export interface TmdbCreditCrew {
credit_id: string;
gender?: number;
Expand Down Expand Up @@ -293,8 +301,10 @@ export interface TmdbTvDetails {
type: string;
vote_average: number;
vote_count: number;
aggregate_credits: {
cast: TmdbAggregateCreditCast[];
};
credits: {
cast: TmdbCreditCast[];
crew: TmdbCreditCrew[];
};
external_ids: TmdbExternalIds;
Expand Down Expand Up @@ -499,7 +509,8 @@ class TheMovieDb {
const response = await this.axios.get<TmdbTvDetails>(`/tv/${tvId}`, {
params: {
language,
append_to_response: 'credits,external_ids,keywords,videos',
append_to_response:
'aggregate_credits,credits,external_ids,keywords,videos',
},
});

Expand Down
4 changes: 2 additions & 2 deletions server/models/Tv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ProductionCompany,
Cast,
Crew,
mapCast,
mapAggregateCast,
mapCrew,
ExternalIds,
mapExternalIds,
Expand Down Expand Up @@ -193,7 +193,7 @@ export const mapTvDetails = (
: undefined,
posterPath: show.poster_path,
credits: {
cast: show.credits.cast.map(mapCast),
cast: show.aggregate_credits.cast.map(mapAggregateCast),
crew: show.credits.crew.map(mapCrew),
},
externalIds: mapExternalIds(show.external_ids),
Expand Down
13 changes: 13 additions & 0 deletions server/models/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
TmdbCreditCast,
TmdbAggregateCreditCast,
TmdbCreditCrew,
TmdbExternalIds,
TmdbVideo,
Expand Down Expand Up @@ -68,6 +69,18 @@ export const mapCast = (person: TmdbCreditCast): Cast => ({
profilePath: person.profile_path,
});

export const mapAggregateCast = (person: TmdbAggregateCreditCast): Cast => ({
castId: person.cast_id,
// the first role is the one for which the actor appears the most as
character: person.roles[0].character,
creditId: person.roles[0].credit_id,
id: person.id,
name: person.name,
order: person.order,
gender: person.gender,
profilePath: person.profile_path,
});

export const mapCrew = (person: TmdbCreditCrew): Crew => ({
creditId: person.credit_id,
department: person.department,
Expand Down

0 comments on commit b239598

Please sign in to comment.