2023-01-14 00:12:56 +01:00
|
|
|
import { MWMediaType } from "./types";
|
|
|
|
|
|
|
|
export const JW_API_BASE = "https://apis.justwatch.com";
|
2023-01-15 16:01:07 +01:00
|
|
|
export const JW_IMAGE_BASE = "https://images.justwatch.com";
|
2023-01-14 00:12:56 +01:00
|
|
|
|
|
|
|
export type JWContentTypes = "movie" | "show";
|
|
|
|
|
|
|
|
export type JWMediaResult = {
|
|
|
|
title: string;
|
|
|
|
poster?: string;
|
|
|
|
id: number;
|
|
|
|
original_release_year: number;
|
|
|
|
jw_entity_id: string;
|
|
|
|
object_type: JWContentTypes;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function mediaTypeToJW(type: MWMediaType): JWContentTypes {
|
|
|
|
if (type === MWMediaType.MOVIE) return "movie";
|
|
|
|
if (type === MWMediaType.SERIES) return "show";
|
|
|
|
throw new Error("unsupported type");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function JWMediaToMediaType(type: string): MWMediaType {
|
|
|
|
if (type === "movie") return MWMediaType.MOVIE;
|
|
|
|
if (type === "show") return MWMediaType.SERIES;
|
|
|
|
throw new Error("unsupported type");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function formatJWMeta(media: JWMediaResult) {
|
|
|
|
const type = JWMediaToMediaType(media.object_type);
|
|
|
|
return {
|
|
|
|
title: media.title,
|
|
|
|
id: media.id.toString(),
|
|
|
|
year: media.original_release_year.toString(),
|
|
|
|
poster: media.poster
|
2023-01-15 16:01:07 +01:00
|
|
|
? `${JW_IMAGE_BASE}${media.poster.replace("{profile}", "s166")}`
|
2023-01-14 00:12:56 +01:00
|
|
|
: undefined,
|
|
|
|
type,
|
|
|
|
};
|
|
|
|
}
|