Merge pull request #35 from Der-Penz/endpoint/tv-episode
Endpoint/tv episode
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tmdb-ts",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"description": "TMDB v3 library wrapper",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { ChangeOption, MediaChanges } from '../types';
|
||||
import { BaseEndpoint } from './base';
|
||||
import { ChangeOptions, MediaChanges } from '../types/changes';
|
||||
|
||||
export class ChangeEndpoint extends BaseEndpoint {
|
||||
constructor(protected readonly accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
async movies(options?: ChangeOptions): Promise<MediaChanges> {
|
||||
async movies(options?: ChangeOption): Promise<MediaChanges> {
|
||||
return await this.api.get<MediaChanges>(`/movie/changes`, options);
|
||||
}
|
||||
|
||||
async tvShows(options?: ChangeOptions): Promise<MediaChanges> {
|
||||
async tvShows(options?: ChangeOption): Promise<MediaChanges> {
|
||||
return await this.api.get<MediaChanges>(`/tv/changes`, options);
|
||||
}
|
||||
|
||||
async person(options?: ChangeOptions): Promise<MediaChanges> {
|
||||
async person(options?: ChangeOption): Promise<MediaChanges> {
|
||||
return await this.api.get<MediaChanges>(`/person/change`, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,3 +14,5 @@ export * from './trending';
|
||||
export * from './find';
|
||||
export * from './keywords';
|
||||
export * from './collections';
|
||||
export * from './tv-episode';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AlternativeTitles,
|
||||
AppendToResponse,
|
||||
AppendToResponseMovieKey,
|
||||
ChangeOptions,
|
||||
ChangeOption,
|
||||
Changes,
|
||||
Credits,
|
||||
ExternalIds,
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Keywords,
|
||||
LanguageOption,
|
||||
LatestMovie,
|
||||
MovieChangeValue,
|
||||
MovieDetails,
|
||||
MovieLists,
|
||||
MoviesPlayingNow,
|
||||
@@ -57,8 +58,8 @@ export class MoviesEndpoint extends BaseEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
async changes(id: number, options?: ChangeOptions): Promise<Changes> {
|
||||
return await this.api.get<Changes>(`${BASE_MOVIE}/${id}/changes`, options);
|
||||
async changes(id: number, options?: ChangeOption): Promise<Changes<MovieChangeValue>> {
|
||||
return await this.api.get<Changes<MovieChangeValue>>(`${BASE_MOVIE}/${id}/changes`, options);
|
||||
}
|
||||
|
||||
async credits(id: number): Promise<Credits> {
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import {
|
||||
AppendToResponse,
|
||||
AppendToResponsePersonKey,
|
||||
ChangeOptions,
|
||||
ChangeOption,
|
||||
ExternalIds,
|
||||
PageOption,
|
||||
PeopleImages,
|
||||
PersonTranslations,
|
||||
PersonChanges,
|
||||
PersonCombinedCredits,
|
||||
PersonDetails,
|
||||
PersonMovieCredit,
|
||||
PersonTvShowCredit,
|
||||
PopularPersons,
|
||||
TaggedImages,
|
||||
Changes,
|
||||
PersonChangeValue,
|
||||
} from '../types';
|
||||
import { BaseEndpoint } from './base';
|
||||
|
||||
@@ -38,8 +39,11 @@ export class PeopleEndpoint extends BaseEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
async changes(id: number, options?: ChangeOptions): Promise<PersonChanges> {
|
||||
return await this.api.get<PersonChanges>(
|
||||
async changes(
|
||||
id: number,
|
||||
options?: ChangeOption
|
||||
): Promise<Changes<PersonChangeValue>> {
|
||||
return await this.api.get<Changes<PersonChangeValue>>(
|
||||
`${BASE_PERSON}/${id}/changes`,
|
||||
options
|
||||
);
|
||||
|
||||
83
src/endpoints/tv-episode.ts
Normal file
83
src/endpoints/tv-episode.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
Episode,
|
||||
EpisodeSelection,
|
||||
LanguageOption,
|
||||
ChangeOption,
|
||||
TvEpisodeCredit,
|
||||
ExternalIds,
|
||||
Images,
|
||||
TvEpisodeTranslations,
|
||||
Videos,
|
||||
AppendToResponseMovieKey,
|
||||
AppendToResponse,
|
||||
Changes,
|
||||
TvEpisodeChangeValue,
|
||||
AppendToResponseTvEpisodeKey,
|
||||
} 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<T extends AppendToResponseTvEpisodeKey[] | undefined>(
|
||||
episodeSelection: EpisodeSelection,
|
||||
appendToResponse?: T,
|
||||
options?: LanguageOption
|
||||
) {
|
||||
const combinedOptions = {
|
||||
append_to_response: appendToResponse
|
||||
? appendToResponse.join(',')
|
||||
: undefined,
|
||||
...options,
|
||||
};
|
||||
|
||||
return await this.api.get<
|
||||
AppendToResponse<Omit<Episode, 'show_id'>, T, 'tvEpisode'>
|
||||
>(`${BASE_EPISODE(episodeSelection)}`, combinedOptions);
|
||||
}
|
||||
|
||||
async changes(episodeID: number, options?: ChangeOption) {
|
||||
return await this.api.get<Changes<TvEpisodeChangeValue>>(
|
||||
`/tv/episode/${episodeID}/changes`,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
async credits(episodeSelection: EpisodeSelection, options?: LanguageOption) {
|
||||
return await this.api.get<TvEpisodeCredit>(
|
||||
`${BASE_EPISODE(episodeSelection)}/credits`,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
async externalIds(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<ExternalIds>(
|
||||
`${BASE_EPISODE(episodeSelection)}/external_ids`
|
||||
);
|
||||
}
|
||||
|
||||
async images(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<Images>(
|
||||
`${BASE_EPISODE(episodeSelection)}/images`
|
||||
);
|
||||
}
|
||||
|
||||
async translations(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<TvEpisodeTranslations>(
|
||||
`${BASE_EPISODE(episodeSelection)}/translations`
|
||||
);
|
||||
}
|
||||
|
||||
async videos(episodeSelection: EpisodeSelection, options?: LanguageOption) {
|
||||
return await this.api.get<Videos>(
|
||||
`${BASE_EPISODE(episodeSelection)}/videos`,
|
||||
options
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AlternativeTitles,
|
||||
AppendToResponse,
|
||||
AppendToResponseTvKey,
|
||||
ChangeOptions,
|
||||
ChangeOption,
|
||||
Changes,
|
||||
ContentRatings,
|
||||
Credits,
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
SimilarTvShows,
|
||||
TopRatedTvShows,
|
||||
Translations,
|
||||
TvShowChangeValue,
|
||||
TvShowDetails,
|
||||
TvShowsAiringToday,
|
||||
Videos,
|
||||
@@ -58,8 +59,8 @@ export class TvShowsEndpoint extends BaseEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
async changes(id: number, options?: ChangeOptions): Promise<Changes> {
|
||||
return await this.api.get<Changes>(`${BASE_TV}/${id}/changes`, options);
|
||||
async changes(id: number, options?: ChangeOption): Promise<Changes<TvShowChangeValue>> {
|
||||
return await this.api.get<Changes<TvShowChangeValue>>(`${BASE_TV}/${id}/changes`, options);
|
||||
}
|
||||
|
||||
async contentRatings(id: number): Promise<ContentRatings> {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -10,26 +10,20 @@ export interface MediaChanges {
|
||||
total_results: number;
|
||||
}
|
||||
|
||||
export interface ChangeOptions {
|
||||
end_date?: string;
|
||||
start_date?: string;
|
||||
page?: number;
|
||||
export interface Changes<T> {
|
||||
changes: Change<T>[];
|
||||
}
|
||||
|
||||
export interface Changes {
|
||||
changes: Change[];
|
||||
}
|
||||
|
||||
export interface Change {
|
||||
export interface Change<T> {
|
||||
key: string;
|
||||
items: ChangeItem[];
|
||||
items: ChangeItem<T>[];
|
||||
}
|
||||
|
||||
export interface ChangeItem {
|
||||
export interface ChangeItem<T> {
|
||||
id: string;
|
||||
action: string;
|
||||
time: string;
|
||||
value: Array<number>;
|
||||
value: T;
|
||||
iso_639_1: string;
|
||||
original_value: Array<number>;
|
||||
original_value: T;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -155,3 +155,14 @@ export interface UpcomingMovies {
|
||||
total_results: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
export type MovieChangeValue =
|
||||
| string
|
||||
| {
|
||||
person_id: number;
|
||||
character: string;
|
||||
order: number;
|
||||
cast_id: number;
|
||||
credit_id: string;
|
||||
}
|
||||
| unknown;
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
MovieLists,
|
||||
PeopleImages,
|
||||
PersonTranslations,
|
||||
PersonChanges,
|
||||
PersonCombinedCredits,
|
||||
PersonMovieCredit,
|
||||
PersonTvShowCredit,
|
||||
@@ -24,6 +23,12 @@ import {
|
||||
Translations,
|
||||
Videos,
|
||||
WatchProviders,
|
||||
PersonChangeValue,
|
||||
MovieChangeValue,
|
||||
TvShowChangeValue,
|
||||
TvEpisodeChangeValue,
|
||||
TvEpisodeCredit,
|
||||
TvEpisodeTranslations,
|
||||
} from '.';
|
||||
|
||||
export interface LanguageOption {
|
||||
@@ -38,6 +43,11 @@ export interface PageOption {
|
||||
page?: number;
|
||||
}
|
||||
|
||||
export interface ChangeOption extends PageOption {
|
||||
start_date?: Date;
|
||||
end_date?: Date;
|
||||
}
|
||||
|
||||
export type AppendToResponseMovieKey =
|
||||
| 'images'
|
||||
| 'videos'
|
||||
@@ -82,12 +92,24 @@ export type AppendToResponsePersonKey =
|
||||
| 'tagged_images'
|
||||
| 'translations';
|
||||
|
||||
export type AppendToResponseTvEpisodeKey =
|
||||
| 'images'
|
||||
| 'credits'
|
||||
| 'external_ids'
|
||||
| 'videos'
|
||||
| 'translations';
|
||||
|
||||
type AppendToResponseAllKeys =
|
||||
| AppendToResponseTvKey
|
||||
| AppendToResponseMovieKey
|
||||
| AppendToResponseTvEpisodeKey
|
||||
| AppendToResponsePersonKey;
|
||||
|
||||
export type AppendToResponseMediaType = 'movie' | 'tvShow' | 'person';
|
||||
export type AppendToResponseMediaType =
|
||||
| 'movie'
|
||||
| 'tvShow'
|
||||
| 'person'
|
||||
| 'tvEpisode';
|
||||
|
||||
export type AppendToResponse<
|
||||
K,
|
||||
@@ -98,7 +120,11 @@ export type AppendToResponse<
|
||||
? object
|
||||
: T extends Array<unknown>
|
||||
? ('credits' extends T[number]
|
||||
? { credits: Omit<Credits, 'id'> }
|
||||
? {
|
||||
credits: Media extends 'tvEpisode'
|
||||
? TvEpisodeCredit
|
||||
: Omit<Credits, 'id'>;
|
||||
}
|
||||
: object) &
|
||||
('videos' extends T[number] ? { videos: Omit<Videos, 'id'> } : object) &
|
||||
('images' extends T[number]
|
||||
@@ -120,9 +146,14 @@ export type AppendToResponse<
|
||||
: object) &
|
||||
('changes' extends T[number]
|
||||
? {
|
||||
changes: Omit<
|
||||
Media extends 'person' ? PersonChanges : Changes,
|
||||
'id'
|
||||
changes: Changes<
|
||||
Media extends 'person'
|
||||
? PersonChangeValue
|
||||
: Media extends 'movie'
|
||||
? MovieChangeValue
|
||||
: Media extends 'tvShow'
|
||||
? TvShowChangeValue
|
||||
: TvEpisodeChangeValue
|
||||
>;
|
||||
}
|
||||
: object) &
|
||||
@@ -142,7 +173,16 @@ export type AppendToResponse<
|
||||
? { external_ids: Omit<ExternalIds, 'id'> }
|
||||
: object) &
|
||||
('translations' extends T[number]
|
||||
? { translations: Omit<Media extends 'person' ? PersonTranslations : Translations, 'id'> }
|
||||
? {
|
||||
translations: Omit<
|
||||
Media extends 'person'
|
||||
? PersonTranslations
|
||||
: Media extends 'tvEpisode'
|
||||
? TvEpisodeTranslations
|
||||
: Translations,
|
||||
'id'
|
||||
>;
|
||||
}
|
||||
: object) &
|
||||
('watch/providers' extends T[number]
|
||||
? { 'watch/providers': Omit<WatchProviders, 'id'> }
|
||||
|
||||
@@ -96,22 +96,13 @@ export interface PersonDetails {
|
||||
homepage: string;
|
||||
}
|
||||
|
||||
export interface PersonChange {
|
||||
id: string;
|
||||
action: string;
|
||||
time: string;
|
||||
iso_639_1: string;
|
||||
iso_3166_1: string;
|
||||
value: string | { profile: { file_path: string } };
|
||||
original_value: string | { profile: { file_path: string } };
|
||||
}
|
||||
|
||||
export interface PersonChanges {
|
||||
changes: {
|
||||
key: string;
|
||||
items: PersonChange[];
|
||||
}[];
|
||||
}
|
||||
export type PersonChangeValue =
|
||||
| string
|
||||
| {
|
||||
profile: {
|
||||
file_path: string;
|
||||
};
|
||||
};
|
||||
|
||||
export interface PopularPersons {
|
||||
page: number;
|
||||
|
||||
58
src/types/tv-episode.ts
Normal file
58
src/types/tv-episode.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
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 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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export type TvEpisodeChangeValue = string | unknown;
|
||||
@@ -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[];
|
||||
@@ -310,3 +279,8 @@ export interface TopRatedTvShows {
|
||||
total_results: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
export interface TvShowChangeValue {
|
||||
season_id: number;
|
||||
season_number: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user