9 Commits

Author SHA1 Message Date
Blake Joynes
1bf4063121 update publish script 2024-06-09 16:54:18 -04:00
Blake Joynes
8df7fe2f2a updates types and add watch providers 2024-06-09 15:53:28 -04:00
Blake Joynes
9ac3da7321 update types and add watch providers 2024-06-09 15:52:54 -04:00
Blake Joynes
313d44878c fix format command 2024-06-09 11:27:04 -04:00
Blake Joynes
6fc8c7b6d3 update dependencies 2024-06-09 11:25:34 -04:00
Blake Joynes
730afebd7d update dependencies 2024-06-09 11:25:19 -04:00
Blake
fc44bcf425 Merge pull request #55 from pypp/fix-poster-sizes
Added size w342 to poster sizes
2024-06-09 11:16:31 -04:00
Netanel Henya
defd0a5998 fix:(types/configuration.ts): added w342 size to the poster sizes 2024-04-03 15:17:19 +03:00
Blake
64ba6e0fd1 Merge pull request #54 from blakejoy/fix/const-enums-in-config-type
update const enums in configuration type
2024-03-30 15:50:48 -04:00
38 changed files with 1861 additions and 3181 deletions

View File

@@ -1,4 +0,0 @@
node_modules
dist
lib
coverage

View File

@@ -1,22 +0,0 @@
module.exports = {
env: {
browser: false,
es2021: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 12,
sourceType: "module",
},
rules:{
'linebreak-style': ['off', 'unix'],
},
plugins: ["@typescript-eslint"],
};

View File

@@ -5,16 +5,16 @@ name: Node.js Package
on:
release:
types: [created]
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: '20.x'
- run: npm ci
- run: npm test
@@ -22,12 +22,13 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: '20.x'
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
- run: npm run compile
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

2
.nvmrc
View File

@@ -1 +1 @@
v18.16.0
v20.14.0

17
eslint.config.mjs Normal file
View File

@@ -0,0 +1,17 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
export default [
{
files: ['src/*.ts'],
ignores: ['node_modules', 'dist', 'lib', 'coverage'],
languageOptions: {
globals: globals.browser,
},
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
eslintPluginPrettierRecommended,
];

3886
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,14 @@
{
"name": "tmdb-ts",
"version": "1.8.0",
"version": "2.0.0",
"description": "TMDB v3 library wrapper",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"compile": "rm -rf dist && tsc -d",
"lint": "eslint --ext .ts src/",
"lint:fix": "eslint --ext .ts src/ --fix",
"format": "npx prettier --write src",
"lint": "eslint src/",
"lint:fix": "eslint --fix",
"format": "prettier --write src",
"pre-commit": "npm run lint"
},
"bugs": {
@@ -29,27 +29,22 @@
"author": "Blake Joynes",
"license": "MIT",
"devDependencies": {
"@types/node": "^18.15.11",
"@types/node-fetch": "^2.5.10",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"dotenv": "^9.0.2",
"eslint": "^8.38.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"prettier": "^2.8.7",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"@eslint/js": "^9.4.0",
"@types/eslint__js": "^8.42.3",
"@types/node": "^20.14.2",
"@types/node-fetch": "^3.0.3",
"dotenv": "^16.4.5",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"globals": "^15.4.0",
"husky": "^9.0.11",
"prettier": "^3.3.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.12.0"
},
"dependencies": {
"cross-fetch": "^3.1.4"
},
"volta": {
"node": "18.16.0",
"yarn": "1.22.4",
"npm": "9.5.1"
"cross-fetch": "^4.0.0"
},
"husky": {
"hooks": {

View File

@@ -1,14 +1,14 @@
import fetch from 'cross-fetch';
import { parseOptions } from './utils';
import { ErrorResponse } from './types';
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
import { BASE_URL_V3 } from './common/constants';
export class Api {
constructor(private accessToken: string) {
this.accessToken = accessToken;
}
/* eslint-disable @typescript-eslint/no-explicit-any */
async get<T>(path: string, options?: Record<string, any>): Promise<T> {
const params = parseOptions(options);
const response = await fetch(`${BASE_URL_V3}${path}?${params}`, {

1
src/common/constants.ts Normal file
View File

@@ -0,0 +1 @@
export const BASE_URL_V3 = 'https://api.themoviedb.org/3';

View File

@@ -15,6 +15,6 @@ export class ChangeEndpoint extends BaseEndpoint {
}
async person(options?: ChangeOption): Promise<MediaChanges> {
return await this.api.get<MediaChanges>(`/person/change`, options);
return await this.api.get<MediaChanges>(`/person/changes`, options);
}
}

View File

@@ -1,6 +1,6 @@
import {
CollectionDetails,
CollectionImageOptions,
DetailedCollection,
ImageCollection,
LanguageOption,
Translations,
@@ -17,8 +17,8 @@ export class CollectionsEndpoint extends BaseEndpoint {
async details(
id: number,
options?: LanguageOption
): Promise<DetailedCollection> {
return await this.api.get<DetailedCollection>(
): Promise<CollectionDetails> {
return await this.api.get<CollectionDetails>(
`${BASE_COLLECTION}/${id}`,
options
);

View File

@@ -1,12 +1,44 @@
import { BaseEndpoint } from './base';
import { Configuration } from '../types/configuration';
import {
Configuration,
CountryConfiguration,
JobConfiguration,
LanguageConfiguration,
TimezoneConfiguration,
} from '../types/configuration';
export class ConfigurationEndpoint extends BaseEndpoint {
constructor(protected readonly accessToken: string) {
super(accessToken);
}
async getCurrent(): Promise<Configuration> {
async getApiConfiguration(): Promise<Configuration> {
return await this.api.get<Configuration>(`/configuration`);
}
async getCountries(): Promise<CountryConfiguration[]> {
return await this.api.get<CountryConfiguration[]>(
`/configuration/countries`
);
}
async getLanguages(): Promise<LanguageConfiguration[]> {
return await this.api.get<LanguageConfiguration[]>(
`/configuration/languages`
);
}
async getJobs(): Promise<JobConfiguration[]> {
return await this.api.get<JobConfiguration[]>(`/configuration/jobs`);
}
async getPrimaryTranslations(): Promise<string[]> {
return await this.api.get<string[]>(`/configuration/primary_translations`);
}
async getTimezones(): Promise<TimezoneConfiguration[]> {
return await this.api.get<TimezoneConfiguration[]>(
`/configuration/timezones`
);
}
}

View File

@@ -1,68 +1,13 @@
import {
MovieDiscoverResult,
SortOption,
MovieQueryOptions,
TvShowDiscoverResult,
TvShowQueryOptions,
} from '../types';
import { BaseEndpoint } from './base';
const BASE_DISCOVER = '/discover';
interface DiscoverQueryOptions {
language?: string;
sort_by?: SortOption;
page?: number;
'vote_average.gte'?: number;
'vote_count.gte'?: number;
'vote_count.lte'?: number;
'vote_average.lte'?: number;
with_watch_providers?: string;
watch_region?: string;
without_companies?: string;
with_watch_monetization_types?: 'flatrate' | 'free' | 'ads' | 'rent' | 'buy';
'with_runtime.gte'?: number;
'with_runtime.lte'?: number;
with_genres?: string;
without_genres?: string;
with_original_language?: string;
without_keywords?: string;
with_keywords?: string;
with_companies?: string;
}
interface MovieQueryOptions extends DiscoverQueryOptions {
region?: string;
certification_country?: string;
certification?: string;
'certification.lte'?: string;
'certification.gte'?: string;
include_adult?: boolean;
include_video?: boolean;
primary_release_year?: number;
'primary_release_date.gte'?: string;
'primary_release_date.lte'?: string;
'release_date.gte'?: string;
'release_date.lte'?: string;
with_release_type?: string;
year?: number;
with_cast?: string;
with_crew?: string;
with_people?: string;
}
interface TvShowQueryOptions extends DiscoverQueryOptions {
'air_date.gte'?: string;
'air_date.lte'?: string;
'first_air_date.gte'?: string;
'first_air_date.lte'?: string;
first_air_date_year?: number;
timezone?: string;
with_networks?: string;
include_null_first_air_dates?: boolean;
screened_theatrically?: boolean;
with_status?: string;
with_type?: string;
}
export class DiscoverEndpoint extends BaseEndpoint {
constructor(accessToken: string) {
super(accessToken);

View File

@@ -6,10 +6,10 @@ export class FindEndpoint extends BaseEndpoint {
super(accessToken);
}
async byId(
externalId: string,
async byExternalId(
id: string,
options: ExternalIdOptions
): Promise<FindResult> {
return await this.api.get<FindResult>(`/find/${externalId}`, options);
return await this.api.get<FindResult>(`/find/${id}`, options);
}
}

View File

@@ -16,3 +16,4 @@ export * from './keywords';
export * from './collections';
export * from './tv-seasons';
export * from './tv-episode';
export * from './watch-providers';

View File

@@ -12,6 +12,10 @@ export class KeywordsEndpoint extends BaseEndpoint {
return await this.api.get<Keyword>(`${BASE_Keyword}/${keywordId}`);
}
/**
*
* @deprecated
*/
async belongingMovies(
keywordId: number,
options?: KeywordsOptions

View File

@@ -10,11 +10,11 @@ import {
PersonDetails,
PersonMovieCredit,
PersonTvShowCredit,
PopularPersons,
TaggedImages,
Changes,
PersonChangeValue,
LanguageOption,
PopularPeople,
} from '../types';
import { BaseEndpoint } from './base';
@@ -90,6 +90,9 @@ export class PeopleEndpoint extends BaseEndpoint {
return await this.api.get<PeopleImages>(`${BASE_PERSON}/${id}/images`);
}
/**
* @deprecated
*/
async taggedImages(id: number, options?: PageOption): Promise<TaggedImages> {
return await this.api.get<TaggedImages>(
`${BASE_PERSON}/${id}/tagged_images`,
@@ -107,12 +110,7 @@ export class PeopleEndpoint extends BaseEndpoint {
return await this.api.get<PersonDetails>(`${BASE_PERSON}/latest`);
}
async popular(
options?: LanguageOption & PageOption
): Promise<PopularPersons> {
return await this.api.get<PopularPersons>(
`${BASE_PERSON}/popular`,
options
);
async popular(options?: LanguageOption & PageOption): Promise<PopularPeople> {
return await this.api.get<PopularPeople>(`${BASE_PERSON}/popular`, options);
}
}

View File

@@ -0,0 +1,40 @@
import { BaseEndpoint } from './base';
import {
LanguageOption,
RegionResult,
WatchProviderResult,
WatchRegionOption,
} from '../types';
type ProviderOptions = WatchRegionOption & LanguageOption;
export class WatchProvidersEndpoint extends BaseEndpoint {
constructor(protected readonly accessToken: string) {
super(accessToken);
}
async getRegions(options?: LanguageOption): Promise<RegionResult> {
return await this.api.get<RegionResult>(
`/watch/providers/regions`,
options
);
}
async getMovieProviders(
options?: ProviderOptions
): Promise<WatchProviderResult> {
return await this.api.get<WatchProviderResult>(
`/watch/providers/movie`,
options
);
}
async getTvProviders(
options?: ProviderOptions
): Promise<WatchProviderResult> {
return await this.api.get<WatchProviderResult>(
`/watch/providers/tv`,
options
);
}
}

View File

@@ -17,6 +17,7 @@ import {
CollectionsEndpoint,
TvSeasonsEndpoint,
TvEpisodesEndpoint,
WatchProvidersEndpoint,
} from './endpoints';
import { CompaniesEndpoint } from './endpoints/companies';
import { NetworksEndpoint } from './endpoints/networks';
@@ -107,4 +108,8 @@ export class TMDB {
get tvSeasons(): TvSeasonsEndpoint {
return new TvSeasonsEndpoint(this.accessToken);
}
get watchProviders(): WatchProvidersEndpoint {
return new WatchProvidersEndpoint(this.accessToken);
}
}

View File

@@ -1,3 +1,5 @@
import { CountryCode } from '../types';
export interface Gravatar {
hash: string;
}
@@ -10,7 +12,7 @@ export interface AccountDetails {
avatar: Avatar;
id: number;
include_adult: boolean;
iso_3166_1: string;
iso_3166_1: CountryCode;
iso_639_1: string;
name: string;
username: string;

View File

@@ -6,14 +6,56 @@ export interface Certification {
export interface Certifications {
certifications: {
US: Certification[];
CA: Certification[];
DE: Certification[];
GB: Certification[];
AR: Certification[];
AT: Certification[];
AU: Certification[];
BG: Certification[];
BR: Certification[];
CA: Certification[];
'CA-QC': Certification[];
CH: Certification[];
CL: Certification[];
CZ: Certification[];
DE: Certification[];
DK: Certification[];
ES: Certification[];
FI: Certification[];
FR: Certification[];
NZ: Certification[];
GB: Certification[];
GR: Certification[];
HK: Certification[];
HU: Certification[];
ID: Certification[];
IE: Certification[];
IL: Certification[];
IN: Certification[];
IT: Certification[];
JP: Certification[];
KR: Certification[];
LT: Certification[];
LU: Certification[];
LV: Certification[];
MO: Certification[];
MX: Certification[];
MY: Certification[];
NL: Certification[];
NO: Certification[];
NZ: Certification[];
PH: Certification[];
PL: Certification[];
PR: Certification[];
PT: Certification[];
RO: Certification[];
RU: Certification[];
SE: Certification[];
SG: Certification[];
SK: Certification[];
TH: Certification[];
TR: Certification[];
TW: Certification[];
UA: Certification[];
US: Certification[];
VI: Certification[];
ZA: Certification[];
};
}

View File

@@ -1,6 +1,6 @@
export interface MediaChange {
id: number;
adult: boolean | undefined;
adult?: boolean;
}
export interface MediaChanges {

View File

@@ -2,16 +2,13 @@ import { LanguageOption, Movie } from '.';
export interface Collection {
id: number;
backdrop_path: string;
name: string;
poster_path: string;
adult: boolean;
original_language: string;
original_name: string;
overview: string;
poster_path: string;
backdrop_path: string;
}
export interface DetailedCollection extends Collection {
export interface CollectionDetails extends Collection {
parts: Movie[];
}

View File

@@ -8,7 +8,7 @@ export interface CompanyDetails {
logo_path: string;
name: string;
origin_country: string;
parent_company: ParentCompany;
parent_company?: ParentCompany;
}
export interface ParentCompany {

View File

@@ -1,3 +1,5 @@
import { CountryCode } from '../types';
export interface ImageConfiguration {
base_url: string;
secure_base_url: string;
@@ -13,100 +15,153 @@ export interface Configuration {
change_keys: ChangeKeys[];
}
export enum BackdropSizes {
W300 = 'w300',
W500 = 'w500',
W780 = 'w780',
W1280 = 'w1280',
ORIGINAL = 'original',
export interface CountryConfiguration {
iso_3166_1: CountryCode;
english_name: string;
native_name: string;
}
export enum LogoSizes {
W45 = 'w45',
W92 = 'w92',
W154 = 'w154',
W185 = 'w185',
W300 = 'w300',
W500 = 'w500',
ORIGINAL = 'original',
export interface LanguageConfiguration {
iso_639_1: string;
english_name: string;
name: string;
}
export enum PosterSizes {
W92 = 'w92',
W154 = 'w154',
W185 = 'w185',
W300 = 'w300',
W500 = 'w500',
W780 = 'w780',
ORIGINAL = 'original',
export interface JobConfiguration {
department: string;
jobs: string[];
}
export enum ProfileSizes {
W45 = 'w45',
W185 = 'w185',
W632 = 'w632',
ORIGINAL = 'original',
export interface TimezoneConfiguration {
iso_3166_1: CountryCode;
zones: string[];
}
export enum StillSizes {
W92 = 'w92',
W185 = 'w185',
W300 = 'w300',
ORIGINAL = 'original',
}
export const MediaSize = {
W45: 'w45',
W92: 'w92',
W154: 'w154',
W185: 'w185',
W300: 'w300',
W342: 'w342',
W500: 'w500',
W632: 'w632',
W780: 'w780',
W1280: 'w1280',
ORIGINAL: 'original',
} as const;
export enum ChangeKeys {
ADULT = 'adult',
AIR_DATE = 'air_date',
ALSO_KNOWN_AS = 'also_known_as',
ALTERNATIVE_TITLES = 'alternative_titles',
BIOGRAPHY = 'biography',
BIRTHDAY = 'birthday',
BUDGET = 'budget',
CAST = 'cast',
CERTIFICATIONS = 'certifications',
CHARACTER_NAMES = 'character_names',
CREATED_BY = 'created_by',
CREW = 'crew',
DEATHDAY = 'deathday',
EPISODE = 'episode',
EPISODE_NUMBER = 'episode_number',
EPISODE_RUN_TIME = 'episode_run_time',
FREEBASE_ID = 'freebase_id',
FREEBASE_MID = 'freebase_mid',
GENERAL = 'general',
GENRES = 'genres',
GUEST_STARS = 'guest_stars',
HOMEPAGE = 'homepage',
IMAGES = 'images',
IMDB_ID = 'imdb_id',
LANGUAGES = 'languages',
NAME = 'name',
NETWORK = 'network',
ORIGIN_COUNTRY = 'origin_country',
ORIGINAL_NAME = 'original_name',
ORIGINAL_TITLE = 'original_title',
OVERVIEW = 'overview',
PARTS = 'parts',
PLACE_OF_BIRTH = 'place_of_birth',
PLOT_KEYWORDS = 'plot_keywords',
PRODUCTION_CODE = 'production_code',
PRODUCTION_COMPANIES = 'production_companies',
PRODUCTION_COUNTRIES = 'production_countries',
RELEASES = 'releases',
REVENUE = 'revenue',
RUNTIME = 'runtime',
SEASON = 'season',
SEASON_NUMBER = 'season_number',
SEASON_REGULAR = 'season_regular',
SPOKEN_LANGUAGES = 'spoken_languages',
STATUS = 'status',
TAGLINE = 'tagline',
TITLE = 'title',
TRANSLATIONS = 'translations',
TVDB_ID = 'tvdb_id',
TVRAGE_ID = 'tvrage_id',
TYPE = 'type',
VIDEO = 'video',
VIDEOS = 'videos',
}
export const BackdropSize = {
W45: 'w45',
W92: 'w92',
W154: 'w154',
W185: 'w185',
W300: 'w300',
W500: 'w500',
W780: 'w780',
W1280: 'w1280',
ORIGINAL: 'original',
} as const;
type BackdropSizes = (typeof BackdropSize)[keyof typeof BackdropSize];
export const LogoSize = {
W45: 'w45',
W92: 'w92',
W154: 'w154',
W185: 'w185',
W300: 'w300',
W500: 'w500',
ORIGINAL: 'original',
} as const;
type LogoSizes = (typeof LogoSize)[keyof typeof LogoSize];
export const PosterSize = {
W92: 'w92',
W154: 'w154',
W185: 'w185',
W300: 'w300',
W342: 'w342',
W500: 'w500',
W780: 'w780',
ORIGINAL: 'original',
} as const;
type PosterSizes = (typeof PosterSize)[keyof typeof PosterSize];
export const ProfileSize = {
W45: 'w45',
W185: 'w185',
W632: 'w632',
ORIGINAL: 'original',
} as const;
type ProfileSizes = (typeof ProfileSize)[keyof typeof ProfileSize];
export const StillSize = {
W92: 'w92',
W185: 'w185',
W300: 'w300',
ORIGINAL: 'original',
} as const;
type StillSizes = (typeof StillSize)[keyof typeof StillSize];
export const ChangeKey = {
ADULT: 'adult',
AIR_DATE: 'air_date',
ALSO_KNOWN_AS: 'also_known_as',
ALTERNATIVE_TITLES: 'alternative_titles',
BIOGRAPHY: 'biography',
BIRTHDAY: 'birthday',
BUDGET: 'budget',
CAST: 'cast',
CERTIFICATIONS: 'certifications',
CHARACTER_NAMES: 'character_names',
CREATED_BY: 'created_by',
CREW: 'crew',
DEATHDAY: 'deathday',
EPISODE: 'episode',
EPISODE_NUMBER: 'episode_number',
EPISODE_RUN_TIME: 'episode_run_time',
FREEBASE_ID: 'freebase_id',
FREEBASE_MID: 'freebase_mid',
GENERAL: 'general',
GENRES: 'genres',
GUEST_STARS: 'guest_stars',
HOMEPAGE: 'homepage',
IMAGES: 'images',
IMDB_ID: 'imdb_id',
LANGUAGES: 'languages',
NAME: 'name',
NETWORK: 'network',
ORIGIN_COUNTRY: 'origin_country',
ORIGINAL_NAME: 'original_name',
ORIGINAL_TITLE: 'original_title',
OVERVIEW: 'overview',
PARTS: 'parts',
PLACE_OF_BIRTH: 'place_of_birth',
PLOT_KEYWORDS: 'plot_keywords',
PRODUCTION_CODE: 'production_code',
PRODUCTION_COMPANIES: 'production_companies',
PRODUCTION_COUNTRIES: 'production_countries',
RELEASES: 'releases',
REVENUE: 'revenue',
RUNTIME: 'runtime',
SEASON: 'season',
SEASON_NUMBER: 'season_number',
SEASON_REGULAR: 'season_regular',
SPOKEN_LANGUAGES: 'spoken_languages',
STATUS: 'status',
TAGLINE: 'tagline',
TITLE: 'title',
TRANSLATIONS: 'translations',
TVDB_ID: 'tvdb_id',
TVRAGE_ID: 'tvrage_id',
TYPE: 'type',
VIDEO: 'video',
VIDEOS: 'videos',
} as const;
type ChangeKeys = (typeof ChangeKey)[keyof typeof ChangeKey];

View File

@@ -1,4 +1,4 @@
import { Image, Person } from './';
import { CountryCode, Image, Person } from './';
export interface CreditSeason {
air_date?: string;
@@ -7,7 +7,7 @@ export interface CreditSeason {
}
export interface Media {
i?: number;
id?: number;
name?: string;
first_air_date?: string;
vote_count?: number;
@@ -15,6 +15,8 @@ export interface Media {
vote_average?: number;
backdrop_path?: string;
genre_ids?: number[];
media_type: string;
adult: boolean;
original_name?: string;
origin_country?: string[];
poster_path?: string;
@@ -36,7 +38,7 @@ export interface CreditResponse {
}
export interface Title {
iso_3166_1: string;
iso_3166_1: CountryCode;
title: string;
type: string;
}
@@ -89,7 +91,7 @@ export interface ImageCollection {
export interface Video {
id: string;
iso_639_1: string;
iso_3166_1: string;
iso_3166_1: CountryCode;
key: string;
name: string;
site: string;

View File

@@ -1,6 +1,67 @@
import { Movie, TV } from '.';
export type MonetizationType = 'flatrate' | 'free' | 'ads' | 'rent' | 'buy';
export interface DiscoverQueryOptions {
language?: string;
sort_by?: SortOption;
page?: number;
'vote_average.gte'?: number;
'vote_count.gte'?: number;
'vote_count.lte'?: number;
'vote_average.lte'?: number;
with_watch_providers?: string;
watch_region?: string;
without_companies?: string;
with_watch_monetization_types?: MonetizationType;
'with_runtime.gte'?: number;
'with_runtime.lte'?: number;
with_genres?: string;
without_genres?: string;
with_original_language?: string;
without_keywords?: string;
with_keywords?: string;
with_companies?: string;
include_adult?: boolean;
}
export interface MovieQueryOptions extends DiscoverQueryOptions {
region?: string;
certification_country?: string;
certification?: string;
'certification.lte'?: string;
'certification.gte'?: string;
include_adult?: boolean;
include_video?: boolean;
primary_release_year?: number;
'primary_release_date.gte'?: string;
'primary_release_date.lte'?: string;
'release_date.gte'?: string;
'release_date.lte'?: string;
with_release_type?: string;
year?: number;
with_cast?: string;
with_crew?: string;
with_people?: string;
}
export interface TvShowQueryOptions extends DiscoverQueryOptions {
'air_date.gte'?: string;
'air_date.lte'?: string;
'first_air_date.gte'?: string;
'first_air_date.lte'?: string;
first_air_date_year?: number;
timezone?: string;
with_networks?: string;
include_null_first_air_dates?: boolean;
screened_theatrically?: boolean;
with_status?: string;
with_type?: string;
}
export type SortOption =
| 'first_air_date.asc'
| 'first_air_date.desc'
| 'popularity.asc'
| 'popularity.desc'
| 'release_date.asc'

View File

@@ -39,6 +39,7 @@ export type KnownFor = MovieWithMediaType | TVWithMediaType;
export interface Person {
id: number;
name: string;
original_name: string;
known_for: KnownFor[];
profile_path: string;
adult: boolean;
@@ -81,6 +82,7 @@ export interface Company {
export interface TV {
id: number;
adult: boolean;
name: string;
first_air_date: string;
backdrop_path: string;
@@ -109,6 +111,13 @@ export interface ExternalIds {
facebook_id: string;
instagram_id: string;
twitter_id: string;
tvdb_id?: number;
freebase_mid?: string;
freebase_id?: string;
tvrage_id?: number;
wikidata_id: string;
tiktok_id?: string;
youtube_id?: string;
id: number;
}
@@ -120,7 +129,7 @@ export interface ProductionCompany {
}
export interface ProductionCountry {
iso_3166_1: string;
iso_3166_1: CountryCode;
name: string;
}
@@ -137,7 +146,7 @@ export interface ContentRatings {
export interface ContentRatingsResult {
descriptor: unknown[];
iso_3166_1: string;
iso_3166_1: CountryCode;
rating: string;
}
@@ -169,9 +178,9 @@ export interface Review {
author: string;
author_details: AuthorDetails;
content: string;
created_at: Date;
created_at: string;
id: string;
updated_at: Date;
updated_at: string;
url: string;
}
@@ -190,7 +199,7 @@ export interface TranslationData {
}
export interface Translation {
iso_3166_1: string;
iso_3166_1: CountryCode;
iso_639_1: string;
name: string;
english_name: string;
@@ -218,3 +227,71 @@ export interface Images {
logos: Image[];
posters: Image[];
}
export const CountryCodes = [
'AE',
'AR',
'AT',
'AU',
'BE',
'BG',
'BO',
'BR',
'CA',
'CH',
'CL',
'CO',
'CR',
'CV',
'CZ',
'DE',
'DK',
'EC',
'EE',
'EG',
'ES',
'FI',
'FR',
'GB',
'GH',
'GR',
'GT',
'HK',
'HN',
'HU',
'ID',
'IE',
'IL',
'IN',
'IT',
'JP',
'LT',
'LV',
'MU',
'MX',
'MY',
'MZ',
'NL',
'NO',
'NZ',
'PE',
'PH',
'PL',
'PT',
'PY',
'RU',
'SA',
'SE',
'SG',
'SI',
'SK',
'TH',
'TR',
'TW',
'UG',
'US',
'VE',
'ZA',
] as const;
export type CountryCode = (typeof CountryCodes)[number];

View File

@@ -1,4 +1,5 @@
import {
CountryCode,
Genre,
Movie,
ProductionCompany,
@@ -52,14 +53,15 @@ export enum ReleaseDateType {
export interface ReleaseDate {
certification: string;
descriptors: string[];
iso_639_1: string;
release_date: Date;
release_date: string;
type: ReleaseDateType;
note: string;
}
export interface ReleaseDateResult {
iso_3166_1: string;
iso_3166_1: CountryCode;
release_dates: ReleaseDate[];
}

View File

@@ -30,10 +30,157 @@ import {
TvEpisodeCredit,
TvEpisodeTranslations,
TvSeasonChangeValue,
CountryCode,
} from '.';
export const AvailableLanguages = [
'af-ZA',
'ar-AE',
'ar-BH',
'ar-EG',
'ar-IQ',
'ar-JO',
'ar-LY',
'ar-MA',
'ar-QA',
'ar-SA',
'ar-TD',
'ar-YE',
'be-BY',
'bg-BG',
'bn-BD',
'br-FR',
'ca-AD',
'ca-ES',
'ch-GU',
'cs-CZ',
'cy-GB',
'da-DK',
'de-AT',
'de-CH',
'de-DE',
'el-CY',
'el-GR',
'en-AG',
'en-AU',
'en-BB',
'en-BZ',
'en-CA',
'en-CM',
'en-GB',
'en-GG',
'en-GH',
'en-GI',
'en-GY',
'en-IE',
'en-JM',
'en-KE',
'en-LC',
'en-MW',
'en-NZ',
'en-PG',
'en-TC',
'en-US',
'en-ZM',
'en-ZW',
'eo-EO',
'es-AR',
'es-CL',
'es-DO',
'es-EC',
'es-ES',
'es-GQ',
'es-GT',
'es-HN',
'es-MX',
'es-NI',
'es-PA',
'es-PE',
'es-PY',
'es-SV',
'es-UY',
'et-EE',
'eu-ES',
'fa-IR',
'fi-FI',
'fr-BF',
'fr-CA',
'fr-CD',
'fr-CI',
'fr-FR',
'fr-GF',
'fr-GP',
'fr-MC',
'fr-ML',
'fr-MU',
'fr-PF',
'ga-IE',
'gd-GB',
'gl-ES',
'he-IL',
'hi-IN',
'hr-HR',
'hu-HU',
'id-ID',
'it-IT',
'it-VA',
'ja-JP',
'ka-GE',
'kk-KZ',
'kn-IN',
'ko-KR',
'ky-KG',
'lt-LT',
'lv-LV',
'ml-IN',
'mr-IN',
'ms-MY',
'ms-SG',
'nb-NO',
'nl-BE',
'nl-NL',
'no-NO',
'pa-IN',
'pl-PL',
'pt-AO',
'pt-BR',
'pt-MZ',
'pt-PT',
'ro-MD',
'ro-RO',
'ru-RU',
'si-LK',
'sk-SK',
'sl-SI',
'sq-AL',
'sq-XK',
'sr-ME',
'sr-RS',
'sv-SE',
'sw-TZ',
'ta-IN',
'te-IN',
'th-TH',
'tl-PH',
'tr-TR',
'uk-UA',
'ur-PK',
'vi-VN',
'zh-CN',
'zh-HK',
'zh-SG',
'zh-TW',
'zu-ZA',
] as const;
export type AvailableLanguage = (typeof AvailableLanguages)[number];
export interface LanguageOption {
language?: string;
language?: AvailableLanguage;
}
export interface WatchRegionOption {
watch_region?: CountryCode;
}
export interface RegionOption {
@@ -49,8 +196,8 @@ export interface PageOption {
}
export interface ChangeOption extends PageOption {
start_date?: Date;
end_date?: Date;
start_date?: string;
end_date?: string;
}
export type AppendToResponseMovieKey =
@@ -129,112 +276,114 @@ export type AppendToResponseMediaType =
export type AppendToResponse<
K,
T extends AppendToResponseAllKeys[] | undefined,
Media extends AppendToResponseMediaType
Media extends AppendToResponseMediaType,
> = K &
(T extends undefined
? object
: T extends Array<unknown>
? ('credits' extends T[number]
? {
credits: Media extends 'tvEpisode'
? TvEpisodeCredit
: Omit<Credits, 'id'>;
}
: object) &
('videos' extends T[number] ? { videos: Omit<Videos, 'id'> } : object) &
('images' extends T[number]
? ('credits' extends T[number]
? {
images: Omit<
Media extends 'person' ? PeopleImages : Images,
'id'
>;
credits: Media extends 'tvEpisode'
? TvEpisodeCredit
: Omit<Credits, 'id'>;
}
: object) &
('recommendations' extends T[number]
? { recommendations: Recommendations }
: object) &
('reviews' extends T[number]
? { reviews: Omit<Reviews, 'id'> }
: object) &
('reviews' extends T[number]
? { reviews: Omit<Translations, 'id'> }
: object) &
('changes' extends T[number]
? {
changes: Changes<
Media extends 'person'
? PersonChangeValue
: Media extends 'movie'
? MovieChangeValue
('videos' extends T[number]
? { videos: Omit<Videos, 'id'> }
: object) &
('images' extends T[number]
? {
images: Omit<
Media extends 'person' ? PeopleImages : Images,
'id'
>;
}
: object) &
('recommendations' extends T[number]
? { recommendations: Recommendations }
: object) &
('reviews' extends T[number]
? { reviews: Omit<Reviews, 'id'> }
: object) &
('reviews' extends T[number]
? { reviews: Omit<Translations, 'id'> }
: object) &
('changes' extends T[number]
? {
changes: Changes<
Media extends 'person'
? PersonChangeValue
: Media extends 'movie'
? MovieChangeValue
: Media extends 'tvShow'
? TvShowChangeValue
: Media extends 'tvSeason'
? TvSeasonChangeValue
: TvEpisodeChangeValue
>;
}
: object) &
('keywords' extends T[number]
? { keywords: Omit<Keywords, 'id'> }
: object) &
('lists' extends T[number]
? { lists: Omit<MovieLists, 'id'> }
: object) &
('release_dates' extends T[number]
? { release_dates: Omit<ReleaseDates, 'id'> }
: object) &
('alternative_titles' extends T[number]
? { alternative_titles: Omit<AlternativeTitles, 'id'> }
: object) &
('external_ids' extends T[number]
? { external_ids: Omit<ExternalIds, 'id'> }
: object) &
('translations' extends T[number]
? {
translations: Omit<
Media extends 'person'
? PersonTranslations
: Media extends 'tvEpisode'
? TvEpisodeTranslations
: Translations,
'id'
>;
}
: object) &
('watch/providers' extends T[number]
? { 'watch/providers': Omit<WatchProviders, 'id'> }
: object) &
('aggregate_credits' extends T[number]
? { aggregate_credits: Omit<Credits, 'id'> }
: object) &
('episode_groups' extends T[number]
? { episode_groups: Omit<EpisodeGroups, 'id'> }
: object) &
('screened_theatrically' extends T[number]
? { screened_theatrically: Omit<ScreenedTheatrically, 'id'> }
: object) &
('similar' extends T[number]
? {
similar: Media extends 'movie'
? SimilarMovies
: Media extends 'tvShow'
? TvShowChangeValue
: Media extends 'tvSeason'
? TvSeasonChangeValue
: TvEpisodeChangeValue
>;
}
: object) &
('keywords' extends T[number]
? { keywords: Omit<Keywords, 'id'> }
: object) &
('lists' extends T[number]
? { lists: Omit<MovieLists, 'id'> }
: object) &
('release_dates' extends T[number]
? { release_dates: Omit<ReleaseDates, 'id'> }
: object) &
('alternative_titles' extends T[number]
? { alternative_titles: Omit<AlternativeTitles, 'id'> }
: object) &
('external_ids' extends T[number]
? { external_ids: Omit<ExternalIds, 'id'> }
: object) &
('translations' extends T[number]
? {
translations: Omit<
Media extends 'person'
? PersonTranslations
: Media extends 'tvEpisode'
? TvEpisodeTranslations
: Translations,
'id'
>;
}
: object) &
('watch/providers' extends T[number]
? { 'watch/providers': Omit<WatchProviders, 'id'> }
: object) &
('aggregate_credits' extends T[number]
? { aggregate_credits: Omit<Credits, 'id'> }
: object) &
('episode_groups' extends T[number]
? { episode_groups: Omit<EpisodeGroups, 'id'> }
: object) &
('screened_theatrically' extends T[number]
? { screened_theatrically: Omit<ScreenedTheatrically, 'id'> }
: object) &
('similar' extends T[number]
? {
similar: Media extends 'movie'
? SimilarMovies
: Media extends 'tvShow'
? SimilarTvShows
: unknown;
}
: object) &
('content_ratings' extends T[number]
? { content_ratings: Omit<ContentRatings, 'id'> }
: object) &
('movie_credits' extends T[number]
? { movie_credits: Omit<PersonMovieCredit, 'id'> }
: object) &
('tv_credits' extends T[number]
? { tv_credits: Omit<PersonTvShowCredit, 'id'> }
: object) &
('combined_credits' extends T[number]
? { combined_credits: Omit<PersonCombinedCredits, 'id'> }
: object) &
('tagged_images' extends T[number]
? { tagged_images: TaggedImages }
: object)
: never);
? SimilarTvShows
: unknown;
}
: object) &
('content_ratings' extends T[number]
? { content_ratings: Omit<ContentRatings, 'id'> }
: object) &
('movie_credits' extends T[number]
? { movie_credits: Omit<PersonMovieCredit, 'id'> }
: object) &
('tv_credits' extends T[number]
? { tv_credits: Omit<PersonTvShowCredit, 'id'> }
: object) &
('combined_credits' extends T[number]
? { combined_credits: Omit<PersonCombinedCredits, 'id'> }
: object) &
('tagged_images' extends T[number]
? { tagged_images: TaggedImages }
: object)
: never);

View File

@@ -1,4 +1,4 @@
import { Image, Movie, Person, TV } from '.';
import { CountryCode, Image, Movie, Person, TV } from '.';
interface Cast {
character: string;
@@ -104,7 +104,7 @@ export type PersonChangeValue =
};
};
export interface PopularPersons {
export interface PopularPeople {
page: number;
results: Person[];
total_results: number;
@@ -140,7 +140,7 @@ export interface TaggedImages {
export interface PersonTranslations {
id: number;
translations: {
iso_3166_1: string;
iso_3166_1: CountryCode;
iso_639_1: string;
name: string;
english_name: string;

7
src/types/regions.ts Normal file
View File

@@ -0,0 +1,7 @@
import { CountryCode } from '../types';
export interface Region {
iso_3166_1: CountryCode;
english_name: string;
native_name: string;
}

View File

@@ -15,10 +15,10 @@ export type TrendingMediaType = MediaType | 'all';
type TrendingResult<T extends TrendingMediaType> = T extends 'tv'
? TV
: T extends 'movie'
? Movie
: T extends 'person'
? Person
: TVWithMediaType | MovieWithMediaType | PersonWithMediaType;
? Movie
: T extends 'person'
? Person
: TVWithMediaType | MovieWithMediaType | PersonWithMediaType;
export interface TrendingResults<T extends TrendingMediaType> {
page: number;

View File

@@ -1,4 +1,4 @@
import { Credits, Crew } from '.';
import { CountryCode, Credits, Crew } from '.';
export interface EpisodeSelection {
tvShowID: number;
@@ -44,7 +44,7 @@ export interface TvEpisodeCredit extends Credits {
export interface TvEpisodeTranslations {
id: number;
translations: {
iso_3166_1: string;
iso_3166_1: CountryCode;
iso_639_1: string;
name: string;
english_name: string;

View File

@@ -1,3 +1,22 @@
import { Region } from './regions';
import { CountryCode } from '../types';
export interface WatchProvider {
display_priorities: { [K in CountryCode]: number };
display_priority: number;
logo_path: string;
provider_id: number;
provider_name: string;
}
export interface RegionResult {
results: Array<Region>;
}
export interface WatchProviderResult {
results: Array<WatchProvider>;
}
export interface Flatrate {
display_priority: number;
logo_path: string;

View File

@@ -12,7 +12,7 @@ export const getFullImagePath = (
baseUrl: string,
fileSize: string,
imagePath: string,
svg = false
svg: boolean = false
): string => {
const imagePathArr = imagePath.split('.');
const imageFormat = svg ? 'svg' : imagePathArr[1];

View File

@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export function parseOptions(options?: Record<string, any>): string {
/* eslint-disable @typescript-eslint/no-explicit-any */
return options ? new URLSearchParams(Object.entries(options)).toString() : '';
}

View File

@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2022" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "CommonJS" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"moduleResolution": "node16",
"moduleResolution": "node",
"sourceMap": true /* Generates corresponding '.map' file. */,
"outDir": "dist" /* Redirect output structure to the directory. */,
"strict": true /* Enable all strict type-checking options. */,