2022-02-17 18:25:12 +01:00
|
|
|
import { CORS_PROXY_URL } from "mw_constants";
|
2022-02-17 18:36:39 +01:00
|
|
|
import { MWMediaType, MWPortableMedia } from "providers/types";
|
2022-02-17 18:25:12 +01:00
|
|
|
|
|
|
|
const getTheFlixUrl = (media: MWPortableMedia, params?: URLSearchParams) => {
|
|
|
|
if (media.mediaType === MWMediaType.MOVIE) {
|
|
|
|
return `https://theflix.to/movie/${media.mediaId}?${params}`;
|
2022-03-06 14:41:51 +01:00
|
|
|
}
|
|
|
|
if (media.mediaType === MWMediaType.SERIES) {
|
2022-03-13 16:55:59 +01:00
|
|
|
return `https://theflix.to/tv-show/${media.mediaId}/season-${media.seasonId}/episode-${media.episodeId}`;
|
2022-02-17 18:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function getDataFromPortableSearch(
|
|
|
|
media: MWPortableMedia
|
|
|
|
): Promise<any> {
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
params.append("movieInfo", media.mediaId);
|
|
|
|
|
|
|
|
const res = await fetch(CORS_PROXY_URL + getTheFlixUrl(media, params)).then(
|
|
|
|
(d) => d.text()
|
|
|
|
);
|
|
|
|
|
|
|
|
const node: Element = Array.from(
|
|
|
|
new DOMParser()
|
|
|
|
.parseFromString(res, "text/html")
|
|
|
|
.querySelectorAll(`script[id="__NEXT_DATA__"]`)
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
if (media.mediaType === MWMediaType.MOVIE) {
|
|
|
|
return JSON.parse(node.innerHTML).props.pageProps.movie;
|
|
|
|
}
|
2022-03-06 14:41:51 +01:00
|
|
|
// must be series here
|
|
|
|
return JSON.parse(node.innerHTML).props.pageProps.selectedTv;
|
2022-02-17 18:25:12 +01:00
|
|
|
}
|