fix movie metadata

This commit is contained in:
castdrian 2023-06-14 07:48:31 +02:00 committed by Adrian Castro
parent 763de37e9e
commit 0e9263b619
2 changed files with 39 additions and 19 deletions

View File

@ -43,6 +43,41 @@ export interface DetailedMeta {
tmdbId?: string; tmdbId?: string;
} }
export function fromatTMDBMetaResult(
details: TMDBShowData | TMDBMovieData,
type: MWMediaType
): TMDBMediaResult | undefined {
let tmdbmeta;
if (type === MWMediaType.MOVIE) {
tmdbmeta = {
id: details.id,
title: (details as TMDBMovieData).title,
object_type: mediaTypeToTMDB(type),
poster: (details as TMDBMovieData).poster_path ?? undefined,
original_release_year: Number(
(details as TMDBMovieData).release_date?.split("-")[0]
),
};
}
if (type === MWMediaType.SERIES) {
tmdbmeta = {
id: details.id,
title: (details as TMDBShowData).name,
object_type: mediaTypeToTMDB(type),
seasons: (details as TMDBShowData).seasons.map((v) => ({
id: v.id,
season_number: v.season_number,
title: v.name,
})),
poster: (details as TMDBMovieData).poster_path ?? undefined,
original_release_year: Number(
(details as TMDBShowData).first_air_date?.split("-")[0]
),
};
}
return tmdbmeta;
}
export async function getMetaFromId( export async function getMetaFromId(
type: MWMediaType, type: MWMediaType,
id: string, id: string,
@ -79,25 +114,8 @@ export async function getMetaFromId(
} }
} }
const tmdbmeta: TMDBMediaResult = { const tmdbmeta = fromatTMDBMetaResult(details, type);
id: details.id, if (!tmdbmeta) return null;
title:
type === MWMediaType.MOVIE
? (details as TMDBMovieData).title
: (details as TMDBShowData).name,
object_type: mediaTypeToTMDB(type),
seasons: (details as TMDBShowData).seasons.map((v) => ({
id: v.id,
season_number: v.season_number,
title: v.name,
})),
poster: (details as TMDBMovieData).poster_path ?? undefined,
original_release_year:
type === MWMediaType.MOVIE
? Number((details as TMDBMovieData).release_date?.split("-")[0])
: Number((details as TMDBShowData).first_air_date?.split("-")[0]),
};
const meta = formatTMDBMeta(tmdbmeta, seasonData); const meta = formatTMDBMeta(tmdbmeta, seasonData);
if (!meta) return null; if (!meta) return null;

View File

@ -29,6 +29,8 @@ export async function searchForMedia(query: MWQuery): Promise<MWMediaMeta[]> {
}) })
); );
console.log(results[0]);
cache.set(query, results, 3600); cache.set(query, results, 3600);
return results; return results;
} }