2022-02-27 20:07:15 +01:00
|
|
|
import { getProviderFromId } from "./methods/helpers";
|
2022-03-06 14:41:51 +01:00
|
|
|
import { MWMedia, MWPortableMedia, MWMediaStream } from "./types";
|
2022-03-06 13:43:32 +01:00
|
|
|
|
2022-02-06 21:42:39 +01:00
|
|
|
export * from "./types";
|
2022-02-27 20:07:15 +01:00
|
|
|
export * from "./methods/helpers";
|
|
|
|
export * from "./methods/providers";
|
|
|
|
export * from "./methods/search";
|
2022-02-06 21:42:39 +01:00
|
|
|
|
2022-02-17 18:25:12 +01:00
|
|
|
/*
|
|
|
|
** Turn media object into a portable media object
|
|
|
|
*/
|
|
|
|
export function convertMediaToPortable(media: MWMedia): MWPortableMedia {
|
|
|
|
return {
|
|
|
|
mediaId: media.mediaId,
|
|
|
|
providerId: media.providerId,
|
|
|
|
mediaType: media.mediaType,
|
2022-03-13 16:55:59 +01:00
|
|
|
episodeId: media.episodeId,
|
|
|
|
seasonId: media.seasonId,
|
2022-02-17 18:25:12 +01:00
|
|
|
};
|
2022-02-06 21:42:39 +01:00
|
|
|
}
|
|
|
|
|
2022-02-17 18:25:12 +01:00
|
|
|
/*
|
|
|
|
** Turn portable media into media object
|
|
|
|
*/
|
|
|
|
export async function convertPortableToMedia(
|
|
|
|
portable: MWPortableMedia
|
|
|
|
): Promise<MWMedia | undefined> {
|
|
|
|
const provider = getProviderFromId(portable.providerId);
|
2022-03-06 14:41:51 +01:00
|
|
|
return provider?.getMediaFromPortable(portable);
|
2022-02-06 21:42:39 +01:00
|
|
|
}
|
2022-02-20 16:45:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
** 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;
|
|
|
|
|
2022-03-06 14:41:51 +01:00
|
|
|
return provider.getStream(media);
|
2022-02-20 16:45:46 +01:00
|
|
|
}
|