tv seasons endpoint

This commit is contained in:
DerPenz
2023-05-08 17:11:56 +02:00
parent b0b6398169
commit f6a5375c8c
6 changed files with 120 additions and 10 deletions

View File

@@ -14,3 +14,4 @@ export * from './trending';
export * from './find';
export * from './keywords';
export * from './collections';
export * from './tv-seasons';

View File

@@ -0,0 +1,97 @@
import {
ChangeOptions,
Changes,
Credits,
ExternalIds,
Images,
LanguageOption,
SeasonDetails,
SeasonSelection,
Translations,
Videos,
} from '..';
import { BaseEndpoint } from './base';
const BASE_SEASON = (seasonSelection: SeasonSelection): string => {
return `/tv/${seasonSelection.tvShowID}/season/${seasonSelection.seasonNumber}`;
};
export class TvSeasonsEndpoint extends BaseEndpoint {
constructor(accessToken: string) {
super(accessToken);
}
async details(seasonSelection: SeasonSelection, options: LanguageOption) {
return await this.api.get<SeasonDetails>(
`${BASE_SEASON(seasonSelection)}`,
options
);
}
async aggregateCredits(
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<Credits>(
`${BASE_SEASON(seasonSelection)}/aggregate_credits`,
options
);
}
async changes(seasonId: number, options: ChangeOptions) {
return await this.api.get<Changes>(
`tv/season/${seasonId}/changes`,
options
);
}
async credits(
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<Credits>(
`${BASE_SEASON(seasonSelection)}/credits`,
options
);
}
async externalIds(
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<ExternalIds>(
`${BASE_SEASON(seasonSelection)}/external_ids`,
options
);
}
async images(
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<Images>(
`${BASE_SEASON(seasonSelection)}/images`,
options
);
}
async videos(
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<Videos>(
`${BASE_SEASON(seasonSelection)}/videos`,
options
);
}
async translations(
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<Translations>(
`${BASE_SEASON(seasonSelection)}/translations`,
options
);
}
}

View File

@@ -15,6 +15,7 @@ import {
FindEndpoint,
KeywordsEndpoint,
CollectionsEndpoint,
TvSeasonsEndpoint,
} from './endpoints';
export class TMDB {
@@ -87,4 +88,8 @@ export class TMDB {
get collections(): CollectionsEndpoint {
return new CollectionsEndpoint(this.accessToken);
}
get tvSeasons() : TvSeasonsEndpoint {
return new TvSeasonsEndpoint(this.accessToken);
}
}

View File

@@ -14,6 +14,7 @@ export * from './trending';
export * from './find';
export * from './keywords';
export * from './collections';
export * from './tv-seasons';
export type MediaType = 'movie' | 'tv' | 'person';

16
src/types/tv-seasons.ts Normal file
View File

@@ -0,0 +1,16 @@
import { Episode } from ".";
export interface SeasonSelection {
tvShowID: number;
seasonNumber: number;
}
export interface SeasonDetails {
air_date: string;
episodes: Episode[];
name: string;
overview: string;
id: number;
poster_path: string | null;
season_number: number;
}

View File

@@ -124,16 +124,6 @@ export interface Episode {
runtime: number;
}
export interface SeasonDetails {
air_date: string;
episodes: Episode[];
name: string;
overview: string;
id: number;
poster_path: string | null;
season_number: number;
}
export interface Network {
id: number;
logo_path: string;