diff --git a/package.json b/package.json index 9773a3e..4f3031a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tmdb-ts", - "version": "1.3.0", + "version": "1.4.0", "description": "TMDB v3 library wrapper", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/endpoints/index.ts b/src/endpoints/index.ts index e08baa8..5e950d5 100644 --- a/src/endpoints/index.ts +++ b/src/endpoints/index.ts @@ -14,5 +14,6 @@ export * from './trending'; export * from './find'; export * from './keywords'; export * from './collections'; +export * from './tv-seasons'; export * from './tv-episode'; diff --git a/src/endpoints/tv-seasons.ts b/src/endpoints/tv-seasons.ts new file mode 100644 index 0000000..68eb7c1 --- /dev/null +++ b/src/endpoints/tv-seasons.ts @@ -0,0 +1,102 @@ +import { + ChangeOption, + Changes, + Credits, + ExternalIds, + Images, + LanguageOption, + TvSeasonChangeValue, + SeasonDetails, + SeasonSelection, + Translations, + Videos, + AppendToResponseTvSeasonKey, + AppendToResponse, +} 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, + appendToResponse?: T, + options?: LanguageOption + ) { + const combinedOptions = { + append_to_response: appendToResponse + ? appendToResponse.join(',') + : undefined, + ...options, + }; + + return await this.api.get>( + `${BASE_SEASON(seasonSelection)}`, + combinedOptions + ); + } + + async aggregateCredits( + seasonSelection: SeasonSelection, + options?: LanguageOption + ) { + return await this.api.get( + `${BASE_SEASON(seasonSelection)}/aggregate_credits`, + options + ); + } + + async changes(seasonId: number, options?: ChangeOption) { + return await this.api.get>( + `/tv/season/${seasonId}/changes`, + options + ); + } + + async credits(seasonSelection: SeasonSelection, options?: LanguageOption) { + return await this.api.get( + `${BASE_SEASON(seasonSelection)}/credits`, + options + ); + } + + async externalIds( + seasonSelection: SeasonSelection, + options?: LanguageOption + ) { + return await this.api.get( + `${BASE_SEASON(seasonSelection)}/external_ids`, + options + ); + } + + async images(seasonSelection: SeasonSelection, options?: LanguageOption) { + return await this.api.get( + `${BASE_SEASON(seasonSelection)}/images`, + options + ); + } + + async videos(seasonSelection: SeasonSelection, options?: LanguageOption) { + return await this.api.get( + `${BASE_SEASON(seasonSelection)}/videos`, + options + ); + } + + async translations( + seasonSelection: SeasonSelection, + options?: LanguageOption + ) { + return await this.api.get( + `${BASE_SEASON(seasonSelection)}/translations`, + options + ); + } +} diff --git a/src/tmdb.ts b/src/tmdb.ts index 3e72afa..5d61502 100644 --- a/src/tmdb.ts +++ b/src/tmdb.ts @@ -15,6 +15,7 @@ import { FindEndpoint, KeywordsEndpoint, CollectionsEndpoint, + TvSeasonsEndpoint, TvEpisodesEndpoint, } from './endpoints'; @@ -92,4 +93,8 @@ export class TMDB { get collections(): CollectionsEndpoint { return new CollectionsEndpoint(this.accessToken); } + + get tvSeasons() : TvSeasonsEndpoint { + return new TvSeasonsEndpoint(this.accessToken); + } } diff --git a/src/types/index.ts b/src/types/index.ts index 0e04011..9da1316 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -15,6 +15,7 @@ export * from './find'; export * from './keywords'; export * from './collections'; export * from './tv-episode'; +export * from './tv-seasons'; export type MediaType = 'movie' | 'tv' | 'person'; diff --git a/src/types/options.ts b/src/types/options.ts index b2ceb61..0432f59 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -29,6 +29,7 @@ import { TvEpisodeChangeValue, TvEpisodeCredit, TvEpisodeTranslations, + TvSeasonChangeValue, } from '.'; export interface LanguageOption { @@ -99,16 +100,26 @@ export type AppendToResponseTvEpisodeKey = | 'videos' | 'translations'; +export type AppendToResponseTvSeasonKey = + | 'images' + | 'credits' + | 'external_ids' + | 'videos' + | 'aggregate_credits' + | 'translations'; + type AppendToResponseAllKeys = | AppendToResponseTvKey | AppendToResponseMovieKey | AppendToResponseTvEpisodeKey + | AppendToResponseTvSeasonKey | AppendToResponsePersonKey; export type AppendToResponseMediaType = | 'movie' | 'tvShow' | 'person' + | 'tvSeason' | 'tvEpisode'; export type AppendToResponse< @@ -153,7 +164,9 @@ export type AppendToResponse< ? MovieChangeValue : Media extends 'tvShow' ? TvShowChangeValue - : TvEpisodeChangeValue + : Media extends 'tvSeason' + ? TvSeasonChangeValue : + TvEpisodeChangeValue >; } : object) & diff --git a/src/types/tv-seasons.ts b/src/types/tv-seasons.ts new file mode 100644 index 0000000..72e3b8f --- /dev/null +++ b/src/types/tv-seasons.ts @@ -0,0 +1,23 @@ +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; +} + +export type TvSeasonChangeValue = + | string + | { + episode_id: number; + episode_number: number; + }; diff --git a/src/types/tv-shows.ts b/src/types/tv-shows.ts index eba1193..5bf4772 100644 --- a/src/types/tv-shows.ts +++ b/src/types/tv-shows.ts @@ -93,16 +93,6 @@ export interface TvShowDetails { vote_count: 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;