UNPKG

@tdanks2000/tmdb-wrapper

Version:

A powerful and easy-to-use TypeScript wrapper for The Movie Database (TMDb) API

1,326 lines (1,301 loc) 58.9 kB
//#region src/@types/endpoints/configuration.ts let BackdropSizes = /* @__PURE__ */ function(BackdropSizes$1) { BackdropSizes$1["W300"] = "w300"; BackdropSizes$1["W500"] = "w500"; BackdropSizes$1["W780"] = "w780"; BackdropSizes$1["W1280"] = "w1280"; BackdropSizes$1["ORIGINAL"] = "original"; return BackdropSizes$1; }({}); let LogoSizes = /* @__PURE__ */ function(LogoSizes$1) { LogoSizes$1["W45"] = "w45"; LogoSizes$1["W92"] = "w92"; LogoSizes$1["W154"] = "w154"; LogoSizes$1["W185"] = "w185"; LogoSizes$1["W300"] = "w300"; LogoSizes$1["W500"] = "w500"; LogoSizes$1["ORIGINAL"] = "original"; return LogoSizes$1; }({}); let PosterSizes = /* @__PURE__ */ function(PosterSizes$1) { PosterSizes$1["W92"] = "w92"; PosterSizes$1["W154"] = "w154"; PosterSizes$1["W185"] = "w185"; PosterSizes$1["W300"] = "w300"; PosterSizes$1["W500"] = "w500"; PosterSizes$1["W780"] = "w780"; PosterSizes$1["ORIGINAL"] = "original"; return PosterSizes$1; }({}); let ProfileSizes = /* @__PURE__ */ function(ProfileSizes$1) { ProfileSizes$1["W45"] = "w45"; ProfileSizes$1["W185"] = "w185"; ProfileSizes$1["W632"] = "w632"; ProfileSizes$1["ORIGINAL"] = "original"; return ProfileSizes$1; }({}); let StillSizes = /* @__PURE__ */ function(StillSizes$1) { StillSizes$1["W92"] = "w92"; StillSizes$1["W185"] = "w185"; StillSizes$1["W300"] = "w300"; StillSizes$1["ORIGINAL"] = "original"; return StillSizes$1; }({}); let ChangeKeys = /* @__PURE__ */ function(ChangeKeys$1) { ChangeKeys$1["ADULT"] = "adult"; ChangeKeys$1["AIR_DATE"] = "air_date"; ChangeKeys$1["ALSO_KNOWN_AS"] = "also_known_as"; ChangeKeys$1["ALTERNATIVE_TITLES"] = "alternative_titles"; ChangeKeys$1["BIOGRAPHY"] = "biography"; ChangeKeys$1["BIRTHDAY"] = "birthday"; ChangeKeys$1["BUDGET"] = "budget"; ChangeKeys$1["CAST"] = "cast"; ChangeKeys$1["CERTIFICATIONS"] = "certifications"; ChangeKeys$1["CHARACTER_NAMES"] = "character_names"; ChangeKeys$1["CREATED_BY"] = "created_by"; ChangeKeys$1["CREW"] = "crew"; ChangeKeys$1["DEATHDAY"] = "deathday"; ChangeKeys$1["EPISODE"] = "episode"; ChangeKeys$1["EPISODE_NUMBER"] = "episode_number"; ChangeKeys$1["EPISODE_RUN_TIME"] = "episode_run_time"; ChangeKeys$1["FREEBASE_ID"] = "freebase_id"; ChangeKeys$1["FREEBASE_MID"] = "freebase_mid"; ChangeKeys$1["GENERAL"] = "general"; ChangeKeys$1["GENRES"] = "genres"; ChangeKeys$1["GUEST_STARS"] = "guest_stars"; ChangeKeys$1["HOMEPAGE"] = "homepage"; ChangeKeys$1["IMAGES"] = "images"; ChangeKeys$1["IMDB_ID"] = "imdb_id"; ChangeKeys$1["LANGUAGES"] = "languages"; ChangeKeys$1["NAME"] = "name"; ChangeKeys$1["NETWORK"] = "network"; ChangeKeys$1["ORIGIN_COUNTRY"] = "origin_country"; ChangeKeys$1["ORIGINAL_NAME"] = "original_name"; ChangeKeys$1["ORIGINAL_TITLE"] = "original_title"; ChangeKeys$1["OVERVIEW"] = "overview"; ChangeKeys$1["PARTS"] = "parts"; ChangeKeys$1["PLACE_OF_BIRTH"] = "place_of_birth"; ChangeKeys$1["PLOT_KEYWORDS"] = "plot_keywords"; ChangeKeys$1["PRODUCTION_CODE"] = "production_code"; ChangeKeys$1["PRODUCTION_COMPANIES"] = "production_companies"; ChangeKeys$1["PRODUCTION_COUNTRIES"] = "production_countries"; ChangeKeys$1["RELEASES"] = "releases"; ChangeKeys$1["REVENUE"] = "revenue"; ChangeKeys$1["RUNTIME"] = "runtime"; ChangeKeys$1["SEASON"] = "season"; ChangeKeys$1["SEASON_NUMBER"] = "season_number"; ChangeKeys$1["SEASON_REGULAR"] = "season_regular"; ChangeKeys$1["SPOKEN_LANGUAGES"] = "spoken_languages"; ChangeKeys$1["STATUS"] = "status"; ChangeKeys$1["TAGLINE"] = "tagline"; ChangeKeys$1["TITLE"] = "title"; ChangeKeys$1["TRANSLATIONS"] = "translations"; ChangeKeys$1["TVDB_ID"] = "tvdb_id"; ChangeKeys$1["TVRAGE_ID"] = "tvrage_id"; ChangeKeys$1["TYPE"] = "type"; ChangeKeys$1["VIDEO"] = "video"; ChangeKeys$1["VIDEOS"] = "videos"; return ChangeKeys$1; }({}); //#endregion //#region src/@types/endpoints/movies.ts let ReleaseDateType = /* @__PURE__ */ function(ReleaseDateType$1) { ReleaseDateType$1[ReleaseDateType$1["Premiere"] = 1] = "Premiere"; ReleaseDateType$1[ReleaseDateType$1["Theatrical (limited)"] = 2] = "Theatrical (limited)"; ReleaseDateType$1[ReleaseDateType$1["Theatrical"] = 3] = "Theatrical"; ReleaseDateType$1[ReleaseDateType$1["Digital"] = 4] = "Digital"; ReleaseDateType$1[ReleaseDateType$1["Physical"] = 5] = "Physical"; ReleaseDateType$1[ReleaseDateType$1["TV"] = 6] = "TV"; return ReleaseDateType$1; }({}); //#endregion //#region src/utils/api.ts const BASE_URL_V3 = "https://api.themoviedb.org/3"; var API = class { apiKey; accessToken; constructor(auth) { if (typeof auth === "string") this.accessToken = auth; else { this.apiKey = auth.apiKey; this.accessToken = auth.accessToken; } } /** * Generic GET: * @template T — response type * @template O — options (query params) type */ async get(path, options) { const rawOptions = { ...options ?? {}, ...this.apiKey ? { api_key: this.apiKey } : {} }; const params = parseOptions(rawOptions); const response = await fetch(`${BASE_URL_V3}${path}?${params}`, { method: "GET", headers: { ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}, "Content-Type": "application/json;charset=utf-8" } }); if (!response.ok) { const error = await response.json(); return Promise.reject(error); } return await response.json(); } }; const parseOptions = (options) => { if (!options) return ""; const entries = []; for (const [key, value] of Object.entries(options)) { if (value === void 0 || value === null) continue; if (Array.isArray(value)) for (const item of value) entries.push([key, String(item)]); else entries.push([key, String(value)]); } return new URLSearchParams(entries).toString(); }; //#endregion //#region src/utils/getimagePath.ts /** * Utility method to construct full url for image * based on configuration * * https://developers.themoviedb.org/3/getting-started/images * @param {string} baseUrl base image url (e.g., 'https://image.tmdb.org/t/p/') * @param {string} fileSize file size (e.g., 'original', 'w500') * @param {string} imagePath raw image path * @param {string} format override image format (e.g., 'svg', 'png', 'jpg') * @returns {string} The complete image URL */ const getFullImagePath = (baseUrl, fileSize, imagePath, format) => { if (!imagePath) return ""; const hasExtension = imagePath.includes("."); if (hasExtension) { const imagePathArr = imagePath.split("."); const imageFormat$1 = format || imagePathArr[1]; return `${baseUrl}${fileSize}${imagePathArr[0]}.${imageFormat$1}`; } const imageFormat = format || "jpg"; return `${baseUrl}${fileSize}${imagePath}.${imageFormat}`; }; /** * Common image sizes available in TMDB */ const ImageSizes = { ORIGINAL: "original", W500: "w500", W300: "w300", W185: "w185", W92: "w92", H632: "h632" }; /** * Image formats supported by TMDB */ const ImageFormats = { JPG: "jpg", PNG: "png", SVG: "svg" }; //#endregion //#region src/@types/models/baseEndpoint.ts var BaseEndpoint = class { api; constructor(auth) { this.auth = auth; this.api = new API(auth); } }; //#endregion //#region src/endpoints/account.ts /** * Represents an endpoint for retrieving account details. */ var AccountEndpoint = class extends BaseEndpoint { /** * Constructs a new AccountEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves account details asynchronously. * @returns {Promise<AccountDetails>} A Promise that resolves with the account details. */ async details() { return await this.api.get("/account"); } }; //#endregion //#region src/endpoints/certification.ts /** * Represents an endpoint for retrieving certifications for movies and TV shows. */ var CertificationEndpoint = class extends BaseEndpoint { /** * Constructs a new CertificationEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves certifications for movies asynchronously. * @returns {Promise<Certifications>} A Promise that resolves with the certifications for movies. */ async movies() { return await this.api.get("/certification/movie/list"); } /** * Retrieves certifications for TV shows asynchronously. * @returns {Promise<Certifications>} A Promise that resolves with the certifications for TV shows. */ async tv() { return await this.api.get("/certification/tv/list"); } }; //#endregion //#region src/endpoints/changes.ts /** * Represents an endpoint for retrieving changes in movies, TV shows, and persons. */ var ChangeEndpoint = class extends BaseEndpoint { /** * Constructs a new ChangeEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves changes in movies asynchronously. * @param {ChangeOption} [options] - Optional parameters for filtering the changes. * @returns {Promise<MediaChanges>} A Promise that resolves with the changes in movies. */ async movies(options) { return await this.api.get("/movie/changes", options); } /** * Retrieves changes in TV shows asynchronously. * @param {ChangeOption} [options] - Optional parameters for filtering the changes. * @returns {Promise<MediaChanges>} A Promise that resolves with the changes in TV shows. */ async tv(options) { return await this.api.get("/tv/changes", options); } /** * Retrieves changes related to persons asynchronously. * @param {ChangeOption} [options] - Optional parameters for filtering the changes. * @returns {Promise<MediaChanges>} A Promise that resolves with the changes related to persons. */ async person(options) { return await this.api.get("/person/change", options); } }; //#endregion //#region src/endpoints/collections.ts const BASE_COLLECTION = "/collection"; /** * Represents an endpoint for accessing collections and their details. */ var CollectionsEndpoint = class extends BaseEndpoint { /** * Constructs a new CollectionsEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific collection asynchronously. * @param {number} id - The ID of the collection. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<DetailedCollection>} A Promise that resolves with the detailed information of the collection. */ async details(id, options) { return await this.api.get(`${BASE_COLLECTION}/${id}`, options); } /** * Retrieves images associated with a specific collection asynchronously. * @param {number} id - The ID of the collection. * @param {CollectionImageOptions} [options] - Optional parameters for specifying image options. * @returns {Promise<ImageCollection>} A Promise that resolves with the collection images. */ async images(id, options) { const computedOptions = { include_image_language: options?.include_image_language?.join(","), language: options?.language }; return await this.api.get(`${BASE_COLLECTION}/${id}/images`, computedOptions); } /** * Retrieves translations for a specific collection asynchronously. * @param {number} id - The ID of the collection. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<Translations>} A Promise that resolves with the translations of the collection. */ async translations(id, options) { return await this.api.get(`${BASE_COLLECTION}/${id}/translations`, options); } }; //#endregion //#region src/endpoints/companies.ts /** * Represents an endpoint for accessing company details and related information. */ var CompaniesEndpoint = class extends BaseEndpoint { /** * Constructs a new CompaniesEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific company asynchronously. * @param {number} id - The ID of the company. * @returns {Promise<CompanyDetails>} A Promise that resolves with the detailed information of the company. */ async details(id) { return await this.api.get(`/company/${id}`); } /** * Retrieves alternative names of a specific company asynchronously. * @param {number} id - The ID of the company. * @returns {Promise<AlternativeNames>} A Promise that resolves with the alternative names of the company. */ async alternativeNames(id) { return await this.api.get(`/company/${id}/alternative_names`); } /** * Retrieves images associated with a specific company asynchronously. * @param {number} id - The ID of the company. * @returns {Promise<CompanyImages>} A Promise that resolves with the images of the company. */ async images(id) { return await this.api.get(`/company/${id}/images`); } }; //#endregion //#region src/endpoints/configuration.ts /** * Represents an endpoint for retrieving current system configuration. */ var ConfigurationEndpoint = class extends BaseEndpoint { /** * Constructs a new ConfigurationEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves the current system configuration asynchronously. * @returns {Promise<Configuration>} A Promise that resolves with the current system configuration. */ async getCurrent() { return await this.api.get("/configuration"); } }; //#endregion //#region src/endpoints/credits.ts /** * Represents an endpoint for retrieving credit details. */ var CreditsEndpoint = class extends BaseEndpoint { /** * Constructs a new CreditsEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves credit details by ID asynchronously. * @param {string} id - The ID of the credit. * @returns {Promise<CreditResponse>} A Promise that resolves with the credit details. */ async getById(id) { return await this.api.get(`/credit/${id}`); } }; //#endregion //#region src/endpoints/discover.ts const BASE_DISCOVER = "/discover"; /** * Represents an endpoint for discovering movies and TV shows based on various criteria. */ var DiscoverEndpoint = class extends BaseEndpoint { /** * Constructs a new DiscoverEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves a list of movies based on the provided query options asynchronously. * @param {MovieQueryOptions} [options] - Optional parameters for refining the movie discovery. * @returns {Promise<MovieDiscoverResult>} A Promise that resolves with the movie discovery results. */ async movie(options) { return await this.api.get(`${BASE_DISCOVER}/movie`, options); } /** * Retrieves a list of TV shows based on the provided query options asynchronously. * @param {TvShowQueryOptions} [options] - Optional parameters for refining the TV show discovery. * @returns {Promise<TvShowDiscoverResult>} A Promise that resolves with the TV show discovery results. */ async tvShow(options) { return await this.api.get(`${BASE_DISCOVER}/tv`, options); } }; //#endregion //#region src/endpoints/find.ts /** * Represents an endpoint for finding media by external ID. */ var FindEndpoint = class extends BaseEndpoint { /** * Constructs a new FindEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves media by external ID asynchronously. * @param {string} externalId - The external ID of the media. * @param {ExternalIdOptions} options - Options for finding media by external ID. * @returns {Promise<FindResult>} A Promise that resolves with the result of the find operation. */ async byId(externalId, options) { return await this.api.get(`/find/${externalId}`, options); } }; //#endregion //#region src/endpoints/genre.ts /** * Represents an endpoint for retrieving genre information for movies and TV shows. */ var GenreEndpoint = class extends BaseEndpoint { /** * Constructs a new GenreEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves genre information for movies asynchronously. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<Genres>} A Promise that resolves with the genre information for movies. */ async movies(options) { return await this.api.get("/genre/movie/list", options); } /** * Retrieves genre information for TV shows asynchronously. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<Genres>} A Promise that resolves with the genre information for TV shows. */ async tv(options) { return await this.api.get("/genre/tv/list", options); } }; //#endregion //#region src/endpoints/keywords.ts const BASE_KEYWORD = "/keyword"; /** * Represents an endpoint for accessing keyword details and related movies. */ var KeywordsEndpoint = class extends BaseEndpoint { /** * Constructs a new KeywordsEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific keyword asynchronously. * @param {number} keywordId - The ID of the keyword. * @returns {Promise<Keyword>} A Promise that resolves with the details of the keyword. */ async details(keywordId) { return await this.api.get(`${BASE_KEYWORD}/${keywordId}`); } /** * Retrieves movies belonging to a specific keyword asynchronously. * @param {number} keywordId - The ID of the keyword. * @param {KeywordsOptions} [options] - Optional parameters for refining the search. * @returns {Promise<BelongingMovies>} A Promise that resolves with the movies belonging to the keyword. */ async belongingMovies(keywordId, options) { return await this.api.get(`${BASE_KEYWORD}/${keywordId}/movies`, options); } }; //#endregion //#region src/endpoints/movies.ts const BASE_MOVIE = "/movie"; /** * Represents an endpoint for accessing movie-related information. */ var MoviesEndpoint = class extends BaseEndpoint { /** * Constructs a new MoviesEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {AppendToResponseMovieKey[]} [appendToResponse] - Optional keys to append to the response. * @param {string} [language] - Optional parameter for specifying the language. * @returns {Promise<AppendToResponse<MovieDetails, AppendToResponseMovieKey[], 'movie'>>} A Promise that resolves with the details of the movie. */ async details(id, appendToResponse, language) { const options = { append_to_response: appendToResponse ? appendToResponse.join(",") : void 0, language }; return await this.api.get(`${BASE_MOVIE}/${id}`, options); } /** * Retrieves alternative titles of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @returns {Promise<AlternativeTitles>} A Promise that resolves with the alternative titles of the movie. */ async alternativeTitles(id) { return await this.api.get(`${BASE_MOVIE}/${id}/alternative_titles`); } /** * Retrieves changes made to a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {ChangeOption} [options] - Optional parameters for filtering changes. * @returns {Promise<Changes<MovieChangeValue>>} A Promise that resolves with the changes made to the movie. */ async changes(id, options) { return await this.api.get(`${BASE_MOVIE}/${id}/changes`, options); } /** * Retrieves credits of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<Credits>} A Promise that resolves with the credits of the movie. */ async credits(id, options) { return await this.api.get(`${BASE_MOVIE}/${id}/credits`, options); } /** * Retrieves external IDs of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @returns {Promise<ExternalIds>} A Promise that resolves with the external IDs of the movie. */ async externalIds(id) { return await this.api.get(`${BASE_MOVIE}/${id}/external_ids`); } /** * Retrieves images of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {MoviesImageSearchOptions} [options] - Optional parameters for specifying image search options. * @returns {Promise<Images>} A Promise that resolves with the images of the movie. */ async images(id, options) { const computedOptions = { include_image_language: options?.include_image_language?.join(","), language: options?.language }; return await this.api.get(`${BASE_MOVIE}/${id}/images`, computedOptions); } /** * Retrieves keywords of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @returns {Promise<Keywords>} A Promise that resolves with the keywords of the movie. */ async keywords(id) { return await this.api.get(`${BASE_MOVIE}/${id}/keywords`); } /** * Retrieves lists containing a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {LanguageOption & PageOption} [options] - Optional parameters for specifying language and pagination options. * @returns {Promise<MovieLists>} A Promise that resolves with the lists containing the movie. */ async lists(id, options) { return await this.api.get(`${BASE_MOVIE}/${id}/lists`, options); } /** * Retrieves recommendations for a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {LanguageOption & PageOption} [options] - Optional parameters for specifying language and pagination options. * @returns {Promise<Recommendations>} A Promise that resolves with the recommendations for the movie. */ async recommendations(id, options) { return await this.api.get(`${BASE_MOVIE}/${id}/recommendations`, options); } /** * Retrieves release dates of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @returns {Promise<ReleaseDates>} A Promise that resolves with the release dates of the movie. */ async releaseDates(id) { return await this.api.get(`${BASE_MOVIE}/${id}/release_dates`); } /** * Retrieves reviews for a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {LanguageOption & PageOption} [options] - Optional parameters for specifying language and pagination options. * @returns {Promise<Reviews>} A Promise that resolves with the reviews for the movie. */ async reviews(id, options) { return await this.api.get(`${BASE_MOVIE}/${id}/reviews`, options); } /** * Retrieves similar movies for a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {LanguageOption & PageOption} [options] - Optional parameters for specifying language and pagination options. * @returns {Promise<SimilarMovies>} A Promise that resolves with the similar movies for the movie. */ async similar(id, options) { return await this.api.get(`${BASE_MOVIE}/${id}/similar`, options); } /** * Retrieves translations of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @returns {Promise<Translations>} A Promise that resolves with the translations of the movie. */ async translations(id) { return await this.api.get(`${BASE_MOVIE}/${id}/translations`); } /** * Retrieves videos of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<Videos>} A Promise that resolves with the videos of the movie. */ async videos(id, options) { return await this.api.get(`${BASE_MOVIE}/${id}/videos`, options); } /** * Retrieves watch providers of a specific movie asynchronously. * @param {number} id - The ID of the movie. * @returns {Promise<WatchProviders>} A Promise that resolves with the watch providers of the movie. */ async watchProviders(id) { return await this.api.get(`${BASE_MOVIE}/${id}/watch/providers`); } /** * Retrieves details of the latest movie asynchronously. * @returns {Promise<LatestMovie>} A Promise that resolves with the details of the latest movie. */ async latest() { return await this.api.get(`${BASE_MOVIE}/latest`); } /** * Retrieves movies playing now asynchronously. * @param {PageOption & LanguageOption & RegionOption} [options] - Optional parameters for specifying language, region, and pagination options. * @returns {Promise<MoviesPlayingNow>} A Promise that resolves with the movies playing now. */ async nowPlaying(options) { return await this.api.get(`${BASE_MOVIE}/now_playing`, options); } /** * Retrieves popular movies asynchronously. * @param {LanguageOption & PageOption} [options] - Optional parameters for specifying language and pagination options. * @returns {Promise<PopularMovies>} A Promise that resolves with the popular movies. */ async popular(options) { return await this.api.get(`${BASE_MOVIE}/popular`, options); } /** * Retrieves top rated movies asynchronously. * @param {PageOption & LanguageOption & RegionOption} [options] - Optional parameters for specifying language, region, and pagination options. * @returns {Promise<TopRatedMovies>} A Promise that resolves with the top rated movies. */ async topRated(options) { return await this.api.get(`${BASE_MOVIE}/top_rated`, options); } /** * Retrieves upcoming movies asynchronously. * @param {PageOption & LanguageOption & RegionOption} [options] - Optional parameters for specifying language, region, and pagination options. * @returns {Promise<UpcomingMovies>} A Promise that resolves with the upcoming movies. */ async upcoming(options) { return await this.api.get(`${BASE_MOVIE}/upcoming`, options); } }; //#endregion //#region src/endpoints/networks.ts /** * Represents an endpoint for accessing network details. */ var NetworksEndpoint = class extends BaseEndpoint { /** * Constructs a new NetworksEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific network asynchronously. * @param {number} id - The ID of the network. * @returns {Promise<NetworkDetails>} A Promise that resolves with the details of the network. */ async details(id) { return await this.api.get(`/network/${id}`); } /** * Retrieves alternative names of a specific network asynchronously. * @param {number} id - The ID of the network. * @returns {Promise<AlternativeNames>} A Promise that resolves with the alternative names of the network. */ async alternativeNames(id) { return await this.api.get(`/network/${id}/alternative_names`); } /** * Retrieves images of a specific network asynchronously. * @param {number} id - The ID of the network. * @returns {Promise<NetworkImages>} A Promise that resolves with the images of the network. */ async images(id) { return await this.api.get(`/network/${id}/images`); } }; //#endregion //#region src/endpoints/people.ts const BASE_PERSON = "/person"; /** * Represents an endpoint for accessing information about people. */ var PeopleEndpoint = class extends BaseEndpoint { /** * Constructs a new PeopleEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific person asynchronously. * @param {number} id - The ID of the person. * @param {AppendToResponsePersonKey[]} [appendToResponse] - Optional keys to append to the response. * @param {string} [language] - Optional parameter for specifying the language. * @returns {Promise<AppendToResponse<PersonDetails, AppendToResponsePersonKey[], 'person'>>} A Promise that resolves with the details of the person. */ async details(id, appendToResponse, language) { const options = { append_to_response: appendToResponse ? appendToResponse.join(",") : void 0, language }; return await this.api.get(`${BASE_PERSON}/${id}`, options); } /** * Retrieves changes made to a specific person asynchronously. * @param {number} id - The ID of the person. * @param {ChangeOption} [options] - Optional parameters for filtering changes. * @returns {Promise<Changes<PersonChangeValue>>} A Promise that resolves with the changes made to the person. */ async changes(id, options) { return await this.api.get(`${BASE_PERSON}/${id}/changes`, options); } /** * Retrieves movie credits of a specific person asynchronously. * @param {number} id - The ID of the person. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<PersonMovieCredit>} A Promise that resolves with the movie credits of the person. */ async movieCredits(id, options) { return await this.api.get(`${BASE_PERSON}/${id}/movie_credits`, options); } /** * Retrieves TV show credits of a specific person asynchronously. * @param {number} id - The ID of the person. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<PersonTvShowCredit>} A Promise that resolves with the TV show credits of the person. */ async tvShowCredits(id, options) { return await this.api.get(`${BASE_PERSON}/${id}/tv_credits`, options); } /** * Retrieves combined credits of a specific person asynchronously. * @param {number} id - The ID of the person. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<PersonCombinedCredits>} A Promise that resolves with the combined credits of the person. */ async combinedCredits(id, options) { return await this.api.get(`${BASE_PERSON}/${id}/combined_credits`, options); } /** * Retrieves external IDs of a specific person asynchronously. * @param {number} id - The ID of the person. * @returns {Promise<ExternalIds>} A Promise that resolves with the external IDs of the person. */ async externalId(id) { return await this.api.get(`${BASE_PERSON}/${id}/external_ids`); } /** * Retrieves images of a specific person asynchronously. * @param {number} id - The ID of the person. * @returns {Promise<PeopleImages>} A Promise that resolves with the images of the person. */ async images(id) { return await this.api.get(`${BASE_PERSON}/${id}/images`); } /** * Retrieves tagged images of a specific person asynchronously. * @param {number} id - The ID of the person. * @param {PageOption} [options] - Optional parameters for specifying pagination options. * @returns {Promise<TaggedImages>} A Promise that resolves with the tagged images of the person. */ async taggedImages(id, options) { return await this.api.get(`${BASE_PERSON}/${id}/tagged_images`, options); } /** * Retrieves translations of a specific person asynchronously. * @param {number} id - The ID of the person. * @returns {Promise<PersonTranslations>} A Promise that resolves with the translations of the person. */ async translation(id) { return await this.api.get(`${BASE_PERSON}/${id}/translations`); } /** * Retrieves details of the latest person asynchronously. * @returns {Promise<PersonDetails>} A Promise that resolves with the details of the latest person. */ async latest() { return await this.api.get(`${BASE_PERSON}/latest`); } /** * Retrieves popular persons asynchronously. * @param {LanguageOption & PageOption} [options] - Optional parameters for specifying language and pagination options. * @returns {Promise<PopularPersons>} A Promise that resolves with the popular persons. */ async popular(options) { return await this.api.get(`${BASE_PERSON}/popular`, options); } }; //#endregion //#region src/endpoints/review.ts /** * Represents an endpoint for accessing review details. */ var ReviewEndpoint = class extends BaseEndpoint { /** * Constructs a new ReviewEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific review asynchronously. * @param {string} id - The ID of the review. * @returns {Promise<ReviewDetails>} A Promise that resolves with the details of the review. */ async details(id) { return await this.api.get(`/review/${id}`); } }; //#endregion //#region src/endpoints/search.ts const BASE_SEARCH = "/search"; /** * Represents an endpoint for performing various search operations. */ var SearchEndpoint = class extends BaseEndpoint { /** * Constructs a new SearchEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Searches for companies asynchronously. * @param {SearchOptions} options - The search options. * @returns {Promise<Search<Company>>} A Promise that resolves with the search results for companies. */ async companies(options) { return await this.api.get(`${BASE_SEARCH}/company`, options); } /** * Searches for collections asynchronously. * @param {SearchOptions} options - The search options. * @returns {Promise<Search<Collection>>} A Promise that resolves with the search results for collections. */ async collections(options) { return await this.api.get(`${BASE_SEARCH}/collection`, options); } /** * Searches for keywords asynchronously. * @param {SearchOptions} options - The search options. * @returns {Promise<Search<{ id: string; name: string }>>} A Promise that resolves with the search results for keywords. */ async keywords(options) { return await this.api.get(`${BASE_SEARCH}/keyword`, options); } /** * Searches for movies asynchronously. * @param {MovieSearchOptions} options - The search options. * @returns {Promise<Search<Movie>>} A Promise that resolves with the search results for movies. */ async movies(options) { return await this.api.get(`${BASE_SEARCH}/movie`, options); } /** * Searches for people asynchronously. * @param {PeopleSearchOptions} options - The search options. * @returns {Promise<Search<Person>>} A Promise that resolves with the search results for people. */ async people(options) { return await this.api.get(`${BASE_SEARCH}/person`, options); } /** * Searches for TV shows asynchronously. * @param {TvSearchOptions} options - The search options. * @returns {Promise<Search<TV>>} A Promise that resolves with the search results for TV shows. */ async tv(options) { return await this.api.get(`${BASE_SEARCH}/tv`, options); } /** * Performs a multi-search asynchronously. * @param {MultiSearchOptions} options - The search options. * @returns {Promise<Search<MultiSearchResult>>} A Promise that resolves with the multi-search results. */ async multi(options) { return await this.api.get(`${BASE_SEARCH}/multi`, options); } }; //#endregion //#region src/endpoints/trending.ts /** * Represents an endpoint for retrieving trending content. */ var TrendingEndpoint = class extends BaseEndpoint { /** * Constructs a new TrendingEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves trending content asynchronously based on media type and time window. * @param {TrendingMediaType} mediaType - The type of media (e.g., 'all', 'movie', 'tv'). * @param {TimeWindow} timeWindow - The time window for trending content (e.g., 'day', 'week'). * @param {LanguageOption & PageOption} [options] - Optional parameters for specifying the language and pagination. * @returns {Promise<TrendingResults<T>>} A Promise that resolves with the trending results. * @template T - The type of media being searched for (e.g., 'movie', 'tv'). */ async trending(mediaType, timeWindow, options) { return await this.api.get(`/trending/${mediaType}/${timeWindow}`, options); } }; //#endregion //#region src/endpoints/tvEpisodes.ts const BASE_EPISODE = (episodeSelection) => { return `/tv/${episodeSelection.tvShowID}/season/${episodeSelection.seasonNumber}/episode/${episodeSelection.episodeNumber}`; }; /** * Represents an endpoint for accessing TV episode-related information. */ var TvEpisodesEndpoint = class extends BaseEndpoint { /** * Constructs a new TvEpisodesEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific TV episode asynchronously. * @param {EpisodeSelection} episodeSelection - The selection criteria for the TV episode. * @param {AppendToResponseTvEpisodeKey[]} [appendToResponse] - Additional data to append to the response. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<AppendToResponse<Omit<Episode, 'show_id'>, AppendToResponseTvEpisodeKey[], 'tvEpisode'>>} * A Promise that resolves with the details of the TV episode. */ async details(episodeSelection, appendToResponse, options) { const combinedOptions = { append_to_response: appendToResponse ? appendToResponse.join(",") : void 0, ...options }; return await this.api.get(`${BASE_EPISODE(episodeSelection)}`, combinedOptions); } /** * Retrieves changes related to a specific TV episode asynchronously. * @param {number} episodeID - The ID of the TV episode. * @param {ChangeOption} [options] - Optional parameters for specifying changes. * @returns {Promise<Changes<TvEpisodeChangeValue>>} A Promise that resolves with the changes related to the TV episode. */ async changes(episodeID, options) { return await this.api.get(`/tv/episode/${episodeID}/changes`, options); } /** * Retrieves credits for a specific TV episode asynchronously. * @param {EpisodeSelection} episodeSelection - The selection criteria for the TV episode. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<TvEpisodeCredit>} A Promise that resolves with the credits for the TV episode. */ async credits(episodeSelection, options) { return await this.api.get(`${BASE_EPISODE(episodeSelection)}/credits`, options); } /** * Retrieves external IDs for a specific TV episode asynchronously. * @param {EpisodeSelection} episodeSelection - The selection criteria for the TV episode. * @returns {Promise<ExternalIds>} A Promise that resolves with the external IDs for the TV episode. */ async externalIds(episodeSelection) { return await this.api.get(`${BASE_EPISODE(episodeSelection)}/external_ids`); } /** * Retrieves images for a specific TV episode asynchronously. * @param {EpisodeSelection} episodeSelection - The selection criteria for the TV episode. * @param {TvEpisodeImageSearchOptions} [options] - Optional parameters for specifying image search options. * @returns {Promise<Images>} A Promise that resolves with the images for the TV episode. */ async images(episodeSelection, options) { const computedOptions = { include_image_language: options?.include_image_language?.join(","), language: options?.language }; return await this.api.get(`${BASE_EPISODE(episodeSelection)}/images`, computedOptions); } /** * Retrieves translations for a specific TV episode asynchronously. * @param {EpisodeSelection} episodeSelection - The selection criteria for the TV episode. * @returns {Promise<TvEpisodeTranslations>} A Promise that resolves with the translations for the TV episode. */ async translations(episodeSelection) { return await this.api.get(`${BASE_EPISODE(episodeSelection)}/translations`); } /** * Retrieves videos for a specific TV episode asynchronously. * @param {EpisodeSelection} episodeSelection - The selection criteria for the TV episode. * @param {TvEpisodeVideoSearchOptions} [options] - Optional parameters for specifying video search options. * @returns {Promise<Videos>} A Promise that resolves with the videos for the TV episode. */ async videos(episodeSelection, options) { const computedOptions = { include_video_language: options?.include_video_language?.join(","), language: options?.language }; return await this.api.get(`${BASE_EPISODE(episodeSelection)}/videos`, computedOptions); } }; //#endregion //#region src/endpoints/tvSeasons.ts const BASE_SEASON = (seasonSelection) => { return `/tv/${seasonSelection.tvShowID}/season/${seasonSelection.seasonNumber}`; }; /** * Represents an endpoint for accessing TV season-related information. */ var TvSeasonsEndpoint = class extends BaseEndpoint { /** * Constructs a new TvSeasonsEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific TV season asynchronously. * @param {SeasonSelection} seasonSelection - The selection criteria for the TV season. * @param {AppendToResponseTvSeasonKey[]} [appendToResponse] - Additional data to append to the response. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<AppendToResponse<SeasonDetails, AppendToResponseTvSeasonKey[], 'tvSeason'>>} * A Promise that resolves with the details of the TV season. */ async details(seasonSelection, appendToResponse, options) { const combinedOptions = { append_to_response: appendToResponse ? appendToResponse.join(",") : void 0, ...options }; return await this.api.get(`${BASE_SEASON(seasonSelection)}`, combinedOptions); } /** * Retrieves aggregate credits for a specific TV season asynchronously. * @param {SeasonSelection} seasonSelection - The selection criteria for the TV season. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<AggregateCredits>} A Promise that resolves with the aggregate credits for the TV season. */ async aggregateCredits(seasonSelection, options) { return await this.api.get(`${BASE_SEASON(seasonSelection)}/aggregate_credits`, options); } /** * Retrieves changes related to a specific TV season asynchronously. * @param {number} seasonId - The ID of the TV season. * @param {ChangeOption} [options] - Optional parameters for specifying changes. * @returns {Promise<Changes<TvSeasonChangeValue>>} A Promise that resolves with the changes related to the TV season. */ async changes(seasonId, options) { return await this.api.get(`/tv/season/${seasonId}/changes`, options); } /** * Retrieves credits for a specific TV season asynchronously. * @param {SeasonSelection} seasonSelection - The selection criteria for the TV season. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<Credits>} A Promise that resolves with the credits for the TV season. */ async credits(seasonSelection, options) { return await this.api.get(`${BASE_SEASON(seasonSelection)}/credits`, options); } /** * Retrieves external IDs for a specific TV season asynchronously. * @param {SeasonSelection} seasonSelection - The selection criteria for the TV season. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<ExternalIds>} A Promise that resolves with the external IDs for the TV season. */ async externalIds(seasonSelection, options) { return await this.api.get(`${BASE_SEASON(seasonSelection)}/external_ids`, options); } /** * Retrieves images for a specific TV season asynchronously. * @param {SeasonSelection} seasonSelection - The selection criteria for the TV season. * @param {TvSeasonImageSearchOptions} [options] - Optional parameters for specifying image search options. * @returns {Promise<Images>} A Promise that resolves with the images for the TV season. */ async images(seasonSelection, options) { const computedOptions = { include_image_language: options?.include_image_language?.join(","), language: options?.language }; return await this.api.get(`${BASE_SEASON(seasonSelection)}/images`, computedOptions); } /** * Retrieves videos for a specific TV season asynchronously. * @param {SeasonSelection} seasonSelection - The selection criteria for the TV season. * @param {TvSeasonVideoSearchOptions} [options] - Optional parameters for specifying video search options. * @returns {Promise<Videos>} A Promise that resolves with the videos for the TV season. */ async videos(seasonSelection, options) { const computedOptions = { include_video_language: options?.include_video_language?.join(","), language: options?.language }; return await this.api.get(`${BASE_SEASON(seasonSelection)}/videos`, computedOptions); } /** * Retrieves translations for a specific TV season asynchronously. * @param {SeasonSelection} seasonSelection - The selection criteria for the TV season. * @param {LanguageOption} [options] - Optional parameters for specifying the language. * @returns {Promise<Translations>} A Promise that resolves with the translations for the TV season. */ async translations(seasonSelection, options) { return await this.api.get(`${BASE_SEASON(seasonSelection)}/translations`, options); } }; //#endregion //#region src/endpoints/tvShows.ts const BASE_TV = "/tv"; /** * Represents an endpoint for accessing TV show-related information. */ var TvShowsEndpoint = class extends BaseEndpoint { /** * Constructs a new TvShowsEndpoint instance. * @param {string} access_token - The access token used for authentication. */ constructor(access_token) { super(access_token); this.access_token = access_token; } /** * Retrieves details of a specific TV show asynchronously. * @param {number} id - The ID of the TV show. * @param {AppendToResponseTvKey[]} [appendToResponse] - Additional data to append to the response. * @param {string} [language] - The language for the response. * @returns {Promise<AppendToResponse<TvShowDetails, AppendToResponseTvKey[], 'tvShow'>>} * A Promise that resolves with the details of the TV show. */ async details(id, appendToResponse, language) { const options = { append_to_response: appendToResponse ? appendToResponse.join(",") : void 0, language }; return await this.api.get(`${BASE_TV}/${id}`, options); } /** * Retrieves alternative titles of a specific TV show asynchronously. * @param {number} id - The ID of the TV show. * @returns {Promise<AlternativeTitles>} A Promise that resolves with the alternative titles of the TV show. */ async alternativeTitles(id) { return await this.api.get(`${BASE_TV}/${id}/alternative_titles`); } /** * Retrieves changes for a specific TV show asynchronously. * @param {number} id - The ID of the TV show. * @param {ChangeOption} [options] - Additional options for the request. * @returns {Promise<Changes<TvShowChangeValue>>} * A Promise that resolves with the changes for the TV show. */ async changes(id, options) { return await this.api.get(`${BASE_TV}/${id}/changes`, options); } /** * Retrieves content ratings for a specific TV show asynchronously. * @param {number} id - The ID of the TV show. * @returns {Promise<ContentRatings>} A Promise that resolves with the content ratings of the TV show. */ async contentRatings(id) { return await this.api.get(`${BASE_TV}/${id}/content_ratings`); } /** * Retrieves aggregate credits for a specific TV show asynchronously. * @param {number} id - The ID of the TV show. * @param {LanguageOption} [options] - Additional options for the request. * @returns {Promise<AggregateCredits>} A Promise that resolves with the aggregate credits of the TV show. */ async aggregateCredits(id, options) { return await this.api.get(`${BASE_TV}/${id}/aggregate_credits`, options); } /** * Retrieves credits for a specific TV show asynchronously. * @param {number} id - The ID of the TV show. * @param {LanguageOption} [options] - Additional options for the request. * @returns {Promise<Credits>} A Promise that resolves with the credits of the TV show. */ async credits(id, options) { return await this.api.get(`${BASE_TV}/${id}/credits`, options); } /** * Retrieves details of a specific season of a TV show asynchronously. * @param {number} tvId - The ID of the TV show. * @param {number} seasonNumber - The season number. * @returns {Promise<SeasonDetails>} A Promise that resolves with the details of the season. */ async season(tvId, seasonNumber) { return await this.api.get(`${BASE_TV}/${tvId}/season/${seasonNumber}`); } /** * Retrieves episode groups for a specific TV show asynchronously. * @param {number} id - The