added find endpoint and types

This commit is contained in:
DerPenz
2023-02-23 18:44:26 +01:00
parent f75321e6a6
commit 4efa4a7354
5 changed files with 47 additions and 0 deletions

14
src/endpoints/find.ts Normal file
View File

@@ -0,0 +1,14 @@
import { BaseEndpoint } from './base';
import querystring from 'querystring';
import { ExternalIdOptions, FindResult } from '../types';
export class FindEndpoint extends BaseEndpoint {
constructor(accessToken: string) {
super(accessToken);
}
async byId(externalId: string, options: ExternalIdOptions): Promise<FindResult> {
const params = querystring.encode(options);
return await this.api.get<FindResult>(`/find/${externalId}?${params}`);
}
}

View File

@@ -13,4 +13,5 @@ export * from './discover';
export * from './people';
export * from './review';
export * from './trending';
export * from './find';

29
src/types/find.ts Normal file
View File

@@ -0,0 +1,29 @@
import { ParsedUrlQueryInput } from 'querystring';
import { Episode, Media, MediaType, Movie, Person, Season, TV } from '.';
export type ExternalSource =
| 'imdb_id'
| 'freebase_mid'
| 'freebase_id'
| 'tvdb_id'
| 'tvrage_id'
| 'facebook_id'
| 'twitter_id'
| 'instagram_id';
export interface ExternalIdOptions extends ParsedUrlQueryInput {
external_source: ExternalSource;
language?: string;
}
type MediaTagged<T> = T & {
media_type: MediaType;
};
export interface FindResult {
movie_results: MediaTagged<Movie>[];
person_results: MediaTagged<Person>[];
tv_results: MediaTagged<TV>[];
tv_episode_results: MediaTagged<Episode>[];
tv_season_results: MediaTagged<Season & { show_id: string }>[];
}

View File

@@ -10,6 +10,7 @@ export * from './people';
export * from './discover';
export * from './review';
export * from './trending';
export * from './find';
export interface AuthorDetails {
name: string;

View File

@@ -100,6 +100,8 @@ export interface Episode {
still_path: string
vote_average: number
vote_count: number
show_id: number;
runtime: number;
}
export interface SeasonDetails {