From 9457dce115fda8688b93bc7b8a6e773bbb52fe6a Mon Sep 17 00:00:00 2001 From: DerPenz Date: Sat, 6 May 2023 18:57:20 +0200 Subject: [PATCH] base tv-episode integration --- src/endpoints/index.ts | 2 + src/endpoints/tv-episode.ts | 83 +++++++++++++++++++++++++++++++++++++ src/tmdb.ts | 5 +++ src/types/index.ts | 1 + src/types/options.ts | 5 +++ src/types/tv-episode.ts | 74 +++++++++++++++++++++++++++++++++ src/types/tv-shows.ts | 33 +-------------- 7 files changed, 171 insertions(+), 32 deletions(-) create mode 100644 src/endpoints/tv-episode.ts create mode 100644 src/types/tv-episode.ts diff --git a/src/endpoints/index.ts b/src/endpoints/index.ts index 6c2fa6a..e08baa8 100644 --- a/src/endpoints/index.ts +++ b/src/endpoints/index.ts @@ -14,3 +14,5 @@ export * from './trending'; export * from './find'; export * from './keywords'; export * from './collections'; +export * from './tv-episode'; + diff --git a/src/endpoints/tv-episode.ts b/src/endpoints/tv-episode.ts new file mode 100644 index 0000000..5988f1b --- /dev/null +++ b/src/endpoints/tv-episode.ts @@ -0,0 +1,83 @@ +import { + Episode, + EpisodeSelection, + LanguageOption, + PageOption, + ChangeOption, + TvEpisodeChanges, + TvEpisodeCredit, + ExternalIds, + Images, + TvEpisodeTranslations, + Videos, + AppendToResponseMovieKey, + AppendToResponse, + } from '..'; + import { BaseEndpoint } from './base'; + + const BASE_EPISODE = (episodeSelection: EpisodeSelection): string => { + return `/tv/${episodeSelection.tvShowID}/season/${episodeSelection.seasonNumber}/episode/${episodeSelection.episodeNumber}`; + }; + + export class TvEpisodesEndpoint extends BaseEndpoint { + constructor(accessToken: string) { + super(accessToken); + } + + async details( + episodeSelection: EpisodeSelection, + appendToResponse?: T, + options?: LanguageOption + ) { + const combinedOptions = { + append_to_response: appendToResponse + ? appendToResponse.join(',') + : undefined, + ...options, + }; + + return await this.api.get< + AppendToResponse, T, 'movie'> + >(`${BASE_EPISODE(episodeSelection)}`, combinedOptions); + } + + async changes(episodeID: number, options?: PageOption & ChangeOption) { + return await this.api.get( + `/tv/episode/${episodeID}/changes`, + options + ); + } + + async credits(episodeSelection: EpisodeSelection, options?: LanguageOption) { + return await this.api.get( + `${BASE_EPISODE(episodeSelection)}/credits`, + options + ); + } + + async externalIds(episodeSelection: EpisodeSelection) { + return await this.api.get( + `${BASE_EPISODE(episodeSelection)}/external_ids` + ); + } + + async images(episodeSelection: EpisodeSelection) { + return await this.api.get( + `${BASE_EPISODE(episodeSelection)}/images` + ); + } + + async translations(episodeSelection: EpisodeSelection) { + return await this.api.get( + `${BASE_EPISODE(episodeSelection)}/translations` + ); + } + + async videos(episodeSelection: EpisodeSelection, options?: LanguageOption) { + return await this.api.get( + `${BASE_EPISODE(episodeSelection)}/videos`, + options + ); + } + } + \ No newline at end of file diff --git a/src/tmdb.ts b/src/tmdb.ts index b0a5416..3e72afa 100644 --- a/src/tmdb.ts +++ b/src/tmdb.ts @@ -15,6 +15,7 @@ import { FindEndpoint, KeywordsEndpoint, CollectionsEndpoint, + TvEpisodesEndpoint, } from './endpoints'; export class TMDB { @@ -60,6 +61,10 @@ export class TMDB { return new TvShowsEndpoint(this.accessToken); } + get tvEpisode(): TvEpisodesEndpoint { + return new TvEpisodesEndpoint(this.accessToken); + } + get discover(): DiscoverEndpoint { return new DiscoverEndpoint(this.accessToken); } diff --git a/src/types/index.ts b/src/types/index.ts index a6f0c0b..0e04011 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-episode'; export type MediaType = 'movie' | 'tv' | 'person'; diff --git a/src/types/options.ts b/src/types/options.ts index af8f924..11556bc 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -38,6 +38,11 @@ export interface PageOption { page?: number; } +export interface ChangeOption extends PageOption { + start_date?: Date; + end_date?: Date; +} + export type AppendToResponseMovieKey = | 'images' | 'videos' diff --git a/src/types/tv-episode.ts b/src/types/tv-episode.ts new file mode 100644 index 0000000..fc7819e --- /dev/null +++ b/src/types/tv-episode.ts @@ -0,0 +1,74 @@ +import { Credits, Crew } from '.'; + +export interface EpisodeSelection { + tvShowID: number; + seasonNumber: number; + episodeNumber: number; +} + +export interface Episode { + air_date: string; + episode_number: number; + crew: Crew[]; + guest_stars: GuestStar[]; + id: number; + name: string; + overview: string; + production_code: string; + season_number: number; + still_path: string; + vote_average: number; + vote_count: number; + runtime: number; + show_id: number; +} + +export interface GuestStar { + credit_id: string; + order: number; + character: string; + adult: boolean; + gender: number | null; + id: number; + known_for_department: string; + name: string; + original_name: string; + popularity: number; + profile_path: string | null; +} + +export interface TvEpisodeChangeItem { + id: string; + action: string; + time: string; + iso_639_1: string; + iso_3166_1: string; + value: string; +} + +export interface TvEpisodeChange { + key: string; + items: TvEpisodeChangeItem[]; +} + +export interface TvEpisodeChanges { + changes: TvEpisodeChange[]; +} + +export interface TvEpisodeCredit extends Credits { + guest_stars: GuestStar[]; +} + +export interface TvEpisodeTranslations { + id: number; + translations: { + iso_3166_1: string; + iso_639_1: string; + name: string; + english_name: string; + data: { + name: string; + overview: string; + }; + }; +} diff --git a/src/types/tv-shows.ts b/src/types/tv-shows.ts index a38f533..6fa34a2 100644 --- a/src/types/tv-shows.ts +++ b/src/types/tv-shows.ts @@ -3,7 +3,7 @@ import { ProductionCompany, ProductionCountry, SpokenLanguage, - Crew, + Episode, } from './'; export interface CreatedBy { @@ -93,37 +93,6 @@ export interface TvShowDetails { vote_count: number; } -export interface GuestStar { - credit_id: string; - order: number; - character: string; - adult: boolean; - gender: number | null; - id: number; - known_for_department: string; - name: string; - original_name: string; - popularity: number; - profile_path: string | null; -} - -export interface Episode { - air_date: string; - episode_number: number; - crew: Crew[]; - guest_stars: GuestStar[]; - id: number; - name: string; - overview: string; - production_code: string; - season_number: number; - still_path: string; - vote_average: number; - vote_count: number; - show_id: number; - runtime: number; -} - export interface SeasonDetails { air_date: string; episodes: Episode[];