Merge branch 'master' into endpoint/tv-season

This commit is contained in:
DerPenz
2023-05-15 13:13:20 +02:00
17 changed files with 267 additions and 103 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "tmdb-ts", "name": "tmdb-ts",
"version": "1.2.0", "version": "1.3.0",
"description": "TMDB v3 library wrapper", "description": "TMDB v3 library wrapper",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@@ -1,20 +1,20 @@
import { ChangeOption, MediaChanges } from '../types';
import { BaseEndpoint } from './base'; import { BaseEndpoint } from './base';
import { ChangeOptions, MediaChanges } from '../types/changes';
export class ChangeEndpoint extends BaseEndpoint { export class ChangeEndpoint extends BaseEndpoint {
constructor(protected readonly accessToken: string) { constructor(protected readonly accessToken: string) {
super(accessToken); super(accessToken);
} }
async movies(options?: ChangeOptions): Promise<MediaChanges> { async movies(options?: ChangeOption): Promise<MediaChanges> {
return await this.api.get<MediaChanges>(`/movie/changes`, options); 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); 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); return await this.api.get<MediaChanges>(`/person/change`, options);
} }
} }

View File

@@ -15,3 +15,5 @@ export * from './find';
export * from './keywords'; export * from './keywords';
export * from './collections'; export * from './collections';
export * from './tv-seasons'; export * from './tv-seasons';
export * from './tv-episode';

View File

@@ -3,7 +3,7 @@ import {
AlternativeTitles, AlternativeTitles,
AppendToResponse, AppendToResponse,
AppendToResponseMovieKey, AppendToResponseMovieKey,
ChangeOptions, ChangeOption,
Changes, Changes,
Credits, Credits,
ExternalIds, ExternalIds,
@@ -11,6 +11,7 @@ import {
Keywords, Keywords,
LanguageOption, LanguageOption,
LatestMovie, LatestMovie,
MovieChangeValue,
MovieDetails, MovieDetails,
MovieLists, MovieLists,
MoviesPlayingNow, MoviesPlayingNow,
@@ -57,8 +58,8 @@ export class MoviesEndpoint extends BaseEndpoint {
); );
} }
async changes(id: number, options?: ChangeOptions): Promise<Changes> { async changes(id: number, options?: ChangeOption): Promise<Changes<MovieChangeValue>> {
return await this.api.get<Changes>(`${BASE_MOVIE}/${id}/changes`, options); return await this.api.get<Changes<MovieChangeValue>>(`${BASE_MOVIE}/${id}/changes`, options);
} }
async credits(id: number): Promise<Credits> { async credits(id: number): Promise<Credits> {

View File

@@ -1,18 +1,19 @@
import { import {
AppendToResponse, AppendToResponse,
AppendToResponsePersonKey, AppendToResponsePersonKey,
ChangeOptions, ChangeOption,
ExternalIds, ExternalIds,
PageOption, PageOption,
PeopleImages, PeopleImages,
PersonTranslations, PersonTranslations,
PersonChanges,
PersonCombinedCredits, PersonCombinedCredits,
PersonDetails, PersonDetails,
PersonMovieCredit, PersonMovieCredit,
PersonTvShowCredit, PersonTvShowCredit,
PopularPersons, PopularPersons,
TaggedImages, TaggedImages,
Changes,
PersonChangeValue,
} from '../types'; } from '../types';
import { BaseEndpoint } from './base'; import { BaseEndpoint } from './base';
@@ -38,8 +39,11 @@ export class PeopleEndpoint extends BaseEndpoint {
); );
} }
async changes(id: number, options?: ChangeOptions): Promise<PersonChanges> { async changes(
return await this.api.get<PersonChanges>( id: number,
options?: ChangeOption
): Promise<Changes<PersonChangeValue>> {
return await this.api.get<Changes<PersonChangeValue>>(
`${BASE_PERSON}/${id}/changes`, `${BASE_PERSON}/${id}/changes`,
options options
); );

View 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
);
}
}

View File

@@ -1,10 +1,11 @@
import { import {
ChangeOptions, ChangeOption,
Changes, Changes,
Credits, Credits,
ExternalIds, ExternalIds,
Images, Images,
LanguageOption, LanguageOption,
SeasonChangeValue,
SeasonDetails, SeasonDetails,
SeasonSelection, SeasonSelection,
Translations, Translations,
@@ -30,7 +31,7 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
async aggregateCredits( async aggregateCredits(
seasonSelection: SeasonSelection, seasonSelection: SeasonSelection,
options: LanguageOption options?: LanguageOption
) { ) {
return await this.api.get<Credits>( return await this.api.get<Credits>(
`${BASE_SEASON(seasonSelection)}/aggregate_credits`, `${BASE_SEASON(seasonSelection)}/aggregate_credits`,
@@ -38,17 +39,14 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
); );
} }
async changes(seasonId: number, options: ChangeOptions) { async changes(seasonId: number, options?: ChangeOption) {
return await this.api.get<Changes>( return await this.api.get<Changes<SeasonChangeValue>>(
`tv/season/${seasonId}/changes`, `/tv/season/${seasonId}/changes`,
options options
); );
} }
async credits( async credits(seasonSelection: SeasonSelection, options?: LanguageOption) {
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<Credits>( return await this.api.get<Credits>(
`${BASE_SEASON(seasonSelection)}/credits`, `${BASE_SEASON(seasonSelection)}/credits`,
options options
@@ -57,7 +55,7 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
async externalIds( async externalIds(
seasonSelection: SeasonSelection, seasonSelection: SeasonSelection,
options: LanguageOption options?: LanguageOption
) { ) {
return await this.api.get<ExternalIds>( return await this.api.get<ExternalIds>(
`${BASE_SEASON(seasonSelection)}/external_ids`, `${BASE_SEASON(seasonSelection)}/external_ids`,
@@ -65,20 +63,14 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
); );
} }
async images( async images(seasonSelection: SeasonSelection, options?: LanguageOption) {
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<Images>( return await this.api.get<Images>(
`${BASE_SEASON(seasonSelection)}/images`, `${BASE_SEASON(seasonSelection)}/images`,
options options
); );
} }
async videos( async videos(seasonSelection: SeasonSelection, options?: LanguageOption) {
seasonSelection: SeasonSelection,
options: LanguageOption
) {
return await this.api.get<Videos>( return await this.api.get<Videos>(
`${BASE_SEASON(seasonSelection)}/videos`, `${BASE_SEASON(seasonSelection)}/videos`,
options options
@@ -87,7 +79,7 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
async translations( async translations(
seasonSelection: SeasonSelection, seasonSelection: SeasonSelection,
options: LanguageOption options?: LanguageOption
) { ) {
return await this.api.get<Translations>( return await this.api.get<Translations>(
`${BASE_SEASON(seasonSelection)}/translations`, `${BASE_SEASON(seasonSelection)}/translations`,

View File

@@ -3,7 +3,7 @@ import {
AlternativeTitles, AlternativeTitles,
AppendToResponse, AppendToResponse,
AppendToResponseTvKey, AppendToResponseTvKey,
ChangeOptions, ChangeOption,
Changes, Changes,
ContentRatings, ContentRatings,
Credits, Credits,
@@ -24,6 +24,7 @@ import {
SimilarTvShows, SimilarTvShows,
TopRatedTvShows, TopRatedTvShows,
Translations, Translations,
TvShowChangeValue,
TvShowDetails, TvShowDetails,
TvShowsAiringToday, TvShowsAiringToday,
Videos, Videos,
@@ -58,8 +59,8 @@ export class TvShowsEndpoint extends BaseEndpoint {
); );
} }
async changes(id: number, options?: ChangeOptions): Promise<Changes> { async changes(id: number, options?: ChangeOption): Promise<Changes<TvShowChangeValue>> {
return await this.api.get<Changes>(`${BASE_TV}/${id}/changes`, options); return await this.api.get<Changes<TvShowChangeValue>>(`${BASE_TV}/${id}/changes`, options);
} }
async contentRatings(id: number): Promise<ContentRatings> { async contentRatings(id: number): Promise<ContentRatings> {

View File

@@ -16,6 +16,7 @@ import {
KeywordsEndpoint, KeywordsEndpoint,
CollectionsEndpoint, CollectionsEndpoint,
TvSeasonsEndpoint, TvSeasonsEndpoint,
TvEpisodesEndpoint,
} from './endpoints'; } from './endpoints';
export class TMDB { export class TMDB {
@@ -61,6 +62,10 @@ export class TMDB {
return new TvShowsEndpoint(this.accessToken); return new TvShowsEndpoint(this.accessToken);
} }
get tvEpisode(): TvEpisodesEndpoint {
return new TvEpisodesEndpoint(this.accessToken);
}
get discover(): DiscoverEndpoint { get discover(): DiscoverEndpoint {
return new DiscoverEndpoint(this.accessToken); return new DiscoverEndpoint(this.accessToken);
} }

View File

@@ -10,26 +10,20 @@ export interface MediaChanges {
total_results: number; total_results: number;
} }
export interface ChangeOptions { export interface Changes<T> {
end_date?: string; changes: Change<T>[];
start_date?: string;
page?: number;
} }
export interface Changes { export interface Change<T> {
changes: Change[];
}
export interface Change {
key: string; key: string;
items: ChangeItem[]; items: ChangeItem<T>[];
} }
export interface ChangeItem { export interface ChangeItem<T> {
id: string; id: string;
action: string; action: string;
time: string; time: string;
value: Array<number>; value: T;
iso_639_1: string; iso_639_1: string;
original_value: Array<number>; original_value: T;
} }

View File

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

View File

@@ -155,3 +155,14 @@ export interface UpcomingMovies {
total_results: number; total_results: number;
total_pages: number; total_pages: number;
} }
export type MovieChangeValue =
| string
| {
person_id: number;
character: string;
order: number;
cast_id: number;
credit_id: string;
}
| unknown;

View File

@@ -10,7 +10,6 @@ import {
MovieLists, MovieLists,
PeopleImages, PeopleImages,
PersonTranslations, PersonTranslations,
PersonChanges,
PersonCombinedCredits, PersonCombinedCredits,
PersonMovieCredit, PersonMovieCredit,
PersonTvShowCredit, PersonTvShowCredit,
@@ -24,6 +23,12 @@ import {
Translations, Translations,
Videos, Videos,
WatchProviders, WatchProviders,
PersonChangeValue,
MovieChangeValue,
TvShowChangeValue,
TvEpisodeChangeValue,
TvEpisodeCredit,
TvEpisodeTranslations,
} from '.'; } from '.';
export interface LanguageOption { export interface LanguageOption {
@@ -38,6 +43,11 @@ export interface PageOption {
page?: number; page?: number;
} }
export interface ChangeOption extends PageOption {
start_date?: Date;
end_date?: Date;
}
export type AppendToResponseMovieKey = export type AppendToResponseMovieKey =
| 'images' | 'images'
| 'videos' | 'videos'
@@ -82,12 +92,24 @@ export type AppendToResponsePersonKey =
| 'tagged_images' | 'tagged_images'
| 'translations'; | 'translations';
export type AppendToResponseTvEpisodeKey =
| 'images'
| 'credits'
| 'external_ids'
| 'videos'
| 'translations';
type AppendToResponseAllKeys = type AppendToResponseAllKeys =
| AppendToResponseTvKey | AppendToResponseTvKey
| AppendToResponseMovieKey | AppendToResponseMovieKey
| AppendToResponseTvEpisodeKey
| AppendToResponsePersonKey; | AppendToResponsePersonKey;
export type AppendToResponseMediaType = 'movie' | 'tvShow' | 'person'; export type AppendToResponseMediaType =
| 'movie'
| 'tvShow'
| 'person'
| 'tvEpisode';
export type AppendToResponse< export type AppendToResponse<
K, K,
@@ -98,7 +120,11 @@ export type AppendToResponse<
? object ? object
: T extends Array<unknown> : T extends Array<unknown>
? ('credits' extends T[number] ? ('credits' extends T[number]
? { credits: Omit<Credits, 'id'> } ? {
credits: Media extends 'tvEpisode'
? TvEpisodeCredit
: Omit<Credits, 'id'>;
}
: object) & : object) &
('videos' extends T[number] ? { videos: Omit<Videos, 'id'> } : object) & ('videos' extends T[number] ? { videos: Omit<Videos, 'id'> } : object) &
('images' extends T[number] ('images' extends T[number]
@@ -120,9 +146,14 @@ export type AppendToResponse<
: object) & : object) &
('changes' extends T[number] ('changes' extends T[number]
? { ? {
changes: Omit< changes: Changes<
Media extends 'person' ? PersonChanges : Changes, Media extends 'person'
'id' ? PersonChangeValue
: Media extends 'movie'
? MovieChangeValue
: Media extends 'tvShow'
? TvShowChangeValue
: TvEpisodeChangeValue
>; >;
} }
: object) & : object) &
@@ -142,7 +173,16 @@ export type AppendToResponse<
? { external_ids: Omit<ExternalIds, 'id'> } ? { external_ids: Omit<ExternalIds, 'id'> }
: object) & : object) &
('translations' extends T[number] ('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) & : object) &
('watch/providers' extends T[number] ('watch/providers' extends T[number]
? { 'watch/providers': Omit<WatchProviders, 'id'> } ? { 'watch/providers': Omit<WatchProviders, 'id'> }

View File

@@ -96,22 +96,13 @@ export interface PersonDetails {
homepage: string; homepage: string;
} }
export interface PersonChange { export type PersonChangeValue =
id: string; | string
action: string; | {
time: string; profile: {
iso_639_1: string; file_path: 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 interface PopularPersons { export interface PopularPersons {
page: number; page: number;

58
src/types/tv-episode.ts Normal file
View 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;

View File

@@ -1,4 +1,4 @@
import { Episode } from "."; import { Episode } from '.';
export interface SeasonSelection { export interface SeasonSelection {
tvShowID: number; tvShowID: number;
@@ -14,3 +14,10 @@ export interface SeasonDetails {
poster_path: string | null; poster_path: string | null;
season_number: number; season_number: number;
} }
export type SeasonChangeValue =
| string
| {
episode_id: number;
episode_number: number;
};

View File

@@ -3,7 +3,7 @@ import {
ProductionCompany, ProductionCompany,
ProductionCountry, ProductionCountry,
SpokenLanguage, SpokenLanguage,
Crew, Episode,
} from './'; } from './';
export interface CreatedBy { export interface CreatedBy {
@@ -93,37 +93,6 @@ export interface TvShowDetails {
vote_count: number; 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 Network { export interface Network {
id: number; id: number;
logo_path: string; logo_path: string;
@@ -300,3 +269,8 @@ export interface TopRatedTvShows {
total_results: number; total_results: number;
total_pages: number; total_pages: number;
} }
export interface TvShowChangeValue {
season_id: number;
season_number: number;
}