feat(tv): show cast for the entire show instead of only the last season (#778)

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

Fixes #775
pull/793/head
Danshil Mungur 4 years ago committed by GitHub
parent e2b800000d
commit b239598e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -3,7 +3,7 @@ import {
ProductionCompany, ProductionCompany,
Cast, Cast,
Crew, Crew,
mapCast, mapAggregateCast,
mapCrew, mapCrew,
ExternalIds, ExternalIds,
mapExternalIds, mapExternalIds,
@ -193,7 +193,7 @@ export const mapTvDetails = (
: undefined, : undefined,
posterPath: show.poster_path, posterPath: show.poster_path,
credits: { credits: {
cast: show.credits.cast.map(mapCast), cast: show.aggregate_credits.cast.map(mapAggregateCast),
crew: show.credits.crew.map(mapCrew), crew: show.credits.crew.map(mapCrew),
}, },
externalIds: mapExternalIds(show.external_ids), externalIds: mapExternalIds(show.external_ids),

@ -1,5 +1,6 @@
import { import {
TmdbCreditCast, TmdbCreditCast,
TmdbAggregateCreditCast,
TmdbCreditCrew, TmdbCreditCrew,
TmdbExternalIds, TmdbExternalIds,
TmdbVideo, TmdbVideo,
@ -68,6 +69,18 @@ export const mapCast = (person: TmdbCreditCast): Cast => ({
profilePath: person.profile_path, 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 => ({ export const mapCrew = (person: TmdbCreditCrew): Crew => ({
creditId: person.credit_id, creditId: person.credit_id,
department: person.department, department: person.department,

Loading…
Cancel
Save