mirror of
https://github.com/movie-web/movie-web.git
synced 2025-02-06 06:38:28 +01:00
0287bdad57
Co-authored-by: William Oldham <wegg7250@gmail.com>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { getProviderFromId } from "./methods/helpers";
|
|
import { MWMedia, MWPortableMedia, MWMediaStream } from "./types";
|
|
import contentCache from "./methods/contentCache";
|
|
|
|
export * from "./types";
|
|
export * from "./methods/helpers";
|
|
export * from "./methods/providers";
|
|
export * from "./methods/search";
|
|
|
|
/*
|
|
** Turn media object into a portable media object
|
|
*/
|
|
export function convertMediaToPortable(media: MWMedia): MWPortableMedia {
|
|
return {
|
|
mediaId: media.mediaId,
|
|
providerId: media.providerId,
|
|
mediaType: media.mediaType,
|
|
episode: media.episode,
|
|
season: media.season,
|
|
};
|
|
}
|
|
|
|
/*
|
|
** Turn portable media into media object
|
|
*/
|
|
export async function convertPortableToMedia(
|
|
portable: MWPortableMedia
|
|
): Promise<MWMedia | undefined> {
|
|
// consult cache first
|
|
const output = contentCache.get(portable);
|
|
if (output) return output;
|
|
|
|
const provider = getProviderFromId(portable.providerId);
|
|
return provider?.getMediaFromPortable(portable);
|
|
}
|
|
|
|
/*
|
|
** find provider from portable and get stream from that provider
|
|
*/
|
|
export async function getStream(
|
|
media: MWPortableMedia
|
|
): Promise<MWMediaStream | undefined> {
|
|
const provider = getProviderFromId(media.providerId);
|
|
if (!provider) return undefined;
|
|
|
|
return provider.getStream(media);
|
|
}
|