From 5a4a9f01f37839ef791d31f7a93a634d4d182edd Mon Sep 17 00:00:00 2001 From: castdrian Date: Fri, 30 Jun 2023 12:57:29 +0200 Subject: [PATCH] cleanup and overlooked refactoring --- src/backend/metadata/getmeta.ts | 21 +++++++++++++++++---- src/backend/metadata/tmdb.ts | 29 +++-------------------------- src/backend/metadata/types/tmdb.ts | 30 ++++++------------------------ 3 files changed, 26 insertions(+), 54 deletions(-) diff --git a/src/backend/metadata/getmeta.ts b/src/backend/metadata/getmeta.ts index b2a84433..199efccb 100644 --- a/src/backend/metadata/getmeta.ts +++ b/src/backend/metadata/getmeta.ts @@ -6,7 +6,6 @@ import { TMDBMediaToMediaType, formatTMDBMeta, getEpisodes, - getExternalIds, getMediaDetails, getMediaPoster, getMovieFromExternalId, @@ -75,8 +74,7 @@ export async function getMetaFromId( if (!details) return null; - const externalIds = await getExternalIds(id, mediaTypeToTMDB(type)); - const imdbId = externalIds.imdb_id ?? undefined; + const imdbId = details.external_ids.imdb_id ?? undefined; let seasonData: TMDBSeasonMetaResult | undefined; @@ -166,7 +164,13 @@ export async function getLegacyMetaFromId( } export function isLegacyUrl(url: string): boolean { - if (url.startsWith("/media/JW")) return true; + if (url.startsWith("/media/JW") || url.startsWith("/media/tmdb-show")) + return true; + return false; +} + +export function isLegacyMediaType(url: string): boolean { + if (url.startsWith("/media/tmdb-show")) return true; return false; } @@ -178,6 +182,15 @@ export async function convertLegacyUrl( const urlParts = url.split("/").slice(2); const [, type, id] = urlParts[0].split("-", 3); + if (isLegacyMediaType(url)) { + const details = await getMediaDetails(id, TMDBContentTypes.TV); + return `/media/${TMDBIdToUrlId( + MWMediaType.SERIES, + details.id.toString(), + details.name + )}`; + } + const mediaType = TMDBMediaToMediaType(type as TMDBContentTypes); const meta = await getLegacyMetaFromId(mediaType, id); diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index 9f42ce4d..d4e75e57 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -7,16 +7,13 @@ import { ExternalIdMovieSearchResult, TMDBContentTypes, TMDBEpisodeShort, - TMDBExternalIds, TMDBMediaResult, TMDBMovieData, - TMDBMovieExternalIds, TMDBMovieSearchResult, TMDBSearchResult, TMDBSeason, TMDBSeasonMetaResult, TMDBShowData, - TMDBShowExternalIds, TMDBShowSearchResult, } from "./types/tmdb"; import { mwFetch } from "../helpers/fetch"; @@ -130,7 +127,7 @@ async function get(url: string, params?: object): Promise { export async function multiSearch( query: string ): Promise<(TMDBMovieSearchResult | TMDBShowSearchResult)[]> { - const data = await get(`search/multi`, { + const data = await get("search/multi", { query, include_adult: false, language: "en-US", @@ -174,10 +171,10 @@ export function getMediaDetails< TReturn = MediaDetailReturn >(id: string, type: T): Promise { if (type === TMDBContentTypes.MOVIE) { - return get(`/movie/${id}`); + return get(`/movie/${id}`, { append_to_response: "external_ids" }); } if (type === TMDBContentTypes.TV) { - return get(`/tv/${id}`); + return get(`/tv/${id}`, { append_to_response: "external_ids" }); } throw new Error("Invalid media type"); } @@ -198,26 +195,6 @@ export async function getEpisodes( })); } -export async function getExternalIds( - id: string, - type: TMDBContentTypes -): Promise { - let data; - - switch (type) { - case TMDBContentTypes.MOVIE: - data = await get(`/movie/${id}/external_ids`); - break; - case TMDBContentTypes.TV: - data = await get(`/tv/${id}/external_ids`); - break; - default: - throw new Error("Invalid media type"); - } - - return data; -} - export async function getMovieFromExternalId( imdbId: string ): Promise { diff --git a/src/backend/metadata/types/tmdb.ts b/src/backend/metadata/types/tmdb.ts index 12cc0d1a..19a85c54 100644 --- a/src/backend/metadata/types/tmdb.ts +++ b/src/backend/metadata/types/tmdb.ts @@ -124,6 +124,9 @@ export interface TMDBShowData { type: string; vote_average: number; vote_count: number; + external_ids: { + imdb_id: string | null; + }; } export interface TMDBMovieData { @@ -172,6 +175,9 @@ export interface TMDBMovieData { video: boolean; vote_average: number; vote_count: number; + external_ids: { + imdb_id: string | null; + }; } export interface TMDBEpisodeResult { @@ -214,30 +220,6 @@ export interface TMDBSeason { 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; - export interface ExternalIdMovieSearchResult { movie_results: { adult: boolean;