feat(search): search by id (#2082)

* feat(search): search by id

This adds the ability to search by ID (starting with TMDb ID).

Since there doesn't seem to be way of searching across movies, tv and persons,
I have to search through all 3 and use the first one in the order: movie -> tv -> person

Searching by ID is triggered using a 'prefix' just like in the *arrs.

* fix: missed some refactoring

* feat(search): use locale language

* feat(search): search using imdb id

* feat(search): search using tvdb id

* fix: alias type import

* fix: missed some refactoring

* fix(search): account for id being a string

* feat(search): account for movies/tvs/persons with the same id

* feat(search): remove non-null assertion

Co-authored-by: Ryan Cohen <ryan@sct.dev>
This commit is contained in:
Danshil Kokil Mungur
2022-01-14 11:52:10 +04:00
committed by GitHub
parent e0b6abe479
commit b31cdbf074
9 changed files with 275 additions and 20 deletions

View File

@@ -1,11 +1,11 @@
import type {
TmdbPersonCreditCast,
TmdbPersonCreditCrew,
TmdbPersonDetail,
TmdbPersonDetails,
} from '../api/themoviedb/interfaces';
import Media from '../entity/Media';
export interface PersonDetail {
export interface PersonDetails {
id: number;
name: string;
birthday: string;
@@ -14,7 +14,7 @@ export interface PersonDetail {
alsoKnownAs?: string[];
gender: number;
biography: string;
popularity: string;
popularity: number;
placeOfBirth?: string;
profilePath?: string;
adult: boolean;
@@ -62,7 +62,7 @@ export interface CombinedCredit {
crew: PersonCreditCrew[];
}
export const mapPersonDetails = (person: TmdbPersonDetail): PersonDetail => ({
export const mapPersonDetails = (person: TmdbPersonDetails): PersonDetails => ({
id: person.id,
name: person.name,
birthday: person.birthday,

View File

@@ -1,6 +1,9 @@
import type {
TmdbMovieDetails,
TmdbMovieResult,
TmdbPersonDetails,
TmdbPersonResult,
TmdbTvDetails,
TmdbTvResult,
} from '../api/themoviedb/interfaces';
import { MediaType as MainMediaType } from '../constants/media';
@@ -140,3 +143,54 @@ export const mapSearchResults = (
return mapPersonResult(result);
}
});
export const mapMovieDetailsToResult = (
movieDetails: TmdbMovieDetails
): TmdbMovieResult => ({
id: movieDetails.id,
media_type: 'movie',
adult: movieDetails.adult,
genre_ids: movieDetails.genres.map((genre) => genre.id),
original_language: movieDetails.original_language,
original_title: movieDetails.original_title,
overview: movieDetails.overview ?? '',
popularity: movieDetails.popularity,
release_date: movieDetails.release_date,
title: movieDetails.title,
video: movieDetails.video,
vote_average: movieDetails.vote_average,
vote_count: movieDetails.vote_count,
backdrop_path: movieDetails.backdrop_path,
poster_path: movieDetails.poster_path,
});
export const mapTvDetailsToResult = (
tvDetails: TmdbTvDetails
): TmdbTvResult => ({
id: tvDetails.id,
media_type: 'tv',
first_air_date: tvDetails.first_air_date,
genre_ids: tvDetails.genres.map((genre) => genre.id),
name: tvDetails.name,
origin_country: tvDetails.origin_country,
original_language: tvDetails.original_language,
original_name: tvDetails.original_name,
overview: tvDetails.overview,
popularity: tvDetails.popularity,
vote_average: tvDetails.vote_average,
vote_count: tvDetails.vote_count,
backdrop_path: tvDetails.backdrop_path,
poster_path: tvDetails.poster_path,
});
export const mapPersonDetailsToResult = (
personDetails: TmdbPersonDetails
): TmdbPersonResult => ({
id: personDetails.id,
media_type: 'person',
name: personDetails.name,
popularity: personDetails.popularity,
adult: personDetails.adult,
profile_path: personDetails.profile_path,
known_for: [],
});