From 205248a376d9347dac3c0f075bf05b3ff280a1f2 Mon Sep 17 00:00:00 2001 From: castdrian Date: Fri, 16 Jun 2023 11:18:32 +0200 Subject: [PATCH] use external ids endpoint for imdb ids --- src/backend/metadata/getmeta.ts | 6 ++---- src/backend/metadata/tmdb.ts | 25 +++++++++++++++++++++++++ src/backend/metadata/types.ts | 24 ++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/backend/metadata/getmeta.ts b/src/backend/metadata/getmeta.ts index a5246fcf..6868c7e4 100644 --- a/src/backend/metadata/getmeta.ts +++ b/src/backend/metadata/getmeta.ts @@ -87,10 +87,8 @@ export async function getMetaFromId( if (!details) return null; - let imdbId; - if (type === MWMediaType.MOVIE) { - imdbId = (details as TMDBMovieData).imdb_id ?? undefined; - } + const externalIds = await Tmdb.getExternalIds(id, mediaTypeToTMDB(type)); + const imdbId = externalIds.imdb_id ?? undefined; let seasonData: TMDBSeasonMetaResult | undefined; diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index aed31c1d..e22e86e7 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -6,15 +6,18 @@ import { MWSeasonMeta, TMDBContentTypes, TMDBEpisodeShort, + TMDBExternalIds, TMDBMediaResult, TMDBMediaStatic, TMDBMovieData, + TMDBMovieExternalIds, TMDBMovieResponse, TMDBMovieResult, TMDBSearchResultStatic, TMDBSeason, TMDBSeasonMetaResult, TMDBShowData, + TMDBShowExternalIds, TMDBShowResponse, TMDBShowResult, } from "./types"; @@ -170,6 +173,28 @@ export abstract class Tmdb { title: e.name, })); } + + public static async getExternalIds( + id: string, + type: TMDBContentTypes + ): Promise { + let data; + + switch (type) { + case "movie": + data = await Tmdb.get( + `/movie/${id}/external_ids` + ); + break; + case "show": + data = await Tmdb.get(`/tv/${id}/external_ids`); + break; + default: + throw new Error("Invalid media type"); + } + + return data; + } } export async function formatTMDBSearchResult( diff --git a/src/backend/metadata/types.ts b/src/backend/metadata/types.ts index e23d9a5b..fa7a7ef0 100644 --- a/src/backend/metadata/types.ts +++ b/src/backend/metadata/types.ts @@ -379,3 +379,27 @@ export interface TMDBSeason { poster_path: string | null; season_number: number; } + +export interface TMDBShowExternalIds { + id: number; + imdb_id: null | string; + freebase_mid: null | string; + freebase_id: null | string; + tvdb_id: number; + tvrage_id: null | string; + wikidata_id: null | string; + facebook_id: null | string; + instagram_id: null | string; + twitter_id: null | string; +} + +export interface TMDBMovieExternalIds { + id: number; + imdb_id: null | string; + wikidata_id: null | string; + facebook_id: null | string; + instagram_id: null | string; + twitter_id: null | string; +} + +export type TMDBExternalIds = TMDBShowExternalIds | TMDBMovieExternalIds;