From f6a5375c8ce816e99920b07c97fb6c7c160c0619 Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 8 May 2023 17:11:56 +0200 Subject: [PATCH 1/3] tv seasons endpoint --- src/endpoints/index.ts | 1 + src/endpoints/tv-seasons.ts | 97 +++++++++++++++++++++++++++++++++++++ src/tmdb.ts | 5 ++ src/types/index.ts | 1 + src/types/tv-seasons.ts | 16 ++++++ src/types/tv-shows.ts | 10 ---- 6 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 src/endpoints/tv-seasons.ts create mode 100644 src/types/tv-seasons.ts diff --git a/src/endpoints/index.ts b/src/endpoints/index.ts index 6c2fa6a..6345ae4 100644 --- a/src/endpoints/index.ts +++ b/src/endpoints/index.ts @@ -14,3 +14,4 @@ export * from './trending'; export * from './find'; export * from './keywords'; export * from './collections'; +export * from './tv-seasons'; diff --git a/src/endpoints/tv-seasons.ts b/src/endpoints/tv-seasons.ts new file mode 100644 index 0000000..045ed0a --- /dev/null +++ b/src/endpoints/tv-seasons.ts @@ -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( + `${BASE_SEASON(seasonSelection)}`, + options + ); + } + + async aggregateCredits( + seasonSelection: SeasonSelection, + options: LanguageOption + ) { + return await this.api.get( + `${BASE_SEASON(seasonSelection)}/aggregate_credits`, + options + ); + } + + async changes(seasonId: number, options: ChangeOptions) { + 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 b0a5416..22107a1 100644 --- a/src/tmdb.ts +++ b/src/tmdb.ts @@ -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); + } } diff --git a/src/types/index.ts b/src/types/index.ts index a6f0c0b..4339a00 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -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'; diff --git a/src/types/tv-seasons.ts b/src/types/tv-seasons.ts new file mode 100644 index 0000000..fbdb497 --- /dev/null +++ b/src/types/tv-seasons.ts @@ -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; +} diff --git a/src/types/tv-shows.ts b/src/types/tv-shows.ts index a38f533..64cea2d 100644 --- a/src/types/tv-shows.ts +++ b/src/types/tv-shows.ts @@ -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; From 00200570972d63d70032b0bcb35905fe78efd338 Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 15 May 2023 13:30:52 +0200 Subject: [PATCH 2/3] append to response tvSeason support --- src/endpoints/tv-seasons.ts | 23 ++++++++++++++++++----- src/types/options.ts | 15 ++++++++++++++- src/types/tv-seasons.ts | 2 +- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/endpoints/tv-seasons.ts b/src/endpoints/tv-seasons.ts index 6b7efb8..68eb7c1 100644 --- a/src/endpoints/tv-seasons.ts +++ b/src/endpoints/tv-seasons.ts @@ -5,11 +5,13 @@ import { ExternalIds, Images, LanguageOption, - SeasonChangeValue, + TvSeasonChangeValue, SeasonDetails, SeasonSelection, Translations, Videos, + AppendToResponseTvSeasonKey, + AppendToResponse, } from '..'; import { BaseEndpoint } from './base'; @@ -22,10 +24,21 @@ export class TvSeasonsEndpoint extends BaseEndpoint { super(accessToken); } - async details(seasonSelection: SeasonSelection, options: LanguageOption) { - return await this.api.get( + 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)}`, - options + combinedOptions ); } @@ -40,7 +53,7 @@ export class TvSeasonsEndpoint extends BaseEndpoint { } async changes(seasonId: number, options?: ChangeOption) { - return await this.api.get>( + return await this.api.get>( `/tv/season/${seasonId}/changes`, options ); 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 index e2a0211..72e3b8f 100644 --- a/src/types/tv-seasons.ts +++ b/src/types/tv-seasons.ts @@ -15,7 +15,7 @@ export interface SeasonDetails { season_number: number; } -export type SeasonChangeValue = +export type TvSeasonChangeValue = | string | { episode_id: number; From f3469510c38c01b5dbea7734e894d988e93ff1d3 Mon Sep 17 00:00:00 2001 From: DerPenz <99838921+Der-Penz@users.noreply.github.com> Date: Sat, 20 May 2023 12:30:27 +0200 Subject: [PATCH 3/3] bumbed version : 1.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",