Added stream scraping

Co-authored-by: James Hawkins <jhawki2005@gmail.com>
This commit is contained in:
Jelle van Snik 2022-02-20 15:49:55 +01:00
parent c763cfe0f0
commit 32b36e047d
4 changed files with 53 additions and 10 deletions

View File

@ -5,7 +5,7 @@ import {
MWQuery, MWQuery,
} from "providers/types"; } from "providers/types";
import { MWProviderMediaResult } from "providers"; import { MWMediaStream, MWProviderMediaResult } from "providers";
export const tempScraper: MWMediaProvider = { export const tempScraper: MWMediaProvider = {
id: "temp", id: "temp",
@ -24,6 +24,14 @@ export const tempScraper: MWMediaProvider = {
}, },
async searchForMedia(query: MWQuery): Promise<MWProviderMediaResult[]> { async searchForMedia(query: MWQuery): Promise<MWProviderMediaResult[]> {
return []; return [
];
},
async getStream(media: MWPortableMedia): Promise<MWMediaStream> {
return {
url: "hi",
type: "mp4",
};
}, },
}; };

View File

@ -2,6 +2,7 @@ import {
MWMediaProvider, MWMediaProvider,
MWMediaType, MWMediaType,
MWPortableMedia, MWPortableMedia,
MWMediaStream,
MWQuery, MWQuery,
} from "providers/types"; } from "providers/types";
@ -13,6 +14,7 @@ import {
import { getDataFromPortableSearch } from "providers/list/theflix/portableToMedia"; import { getDataFromPortableSearch } from "providers/list/theflix/portableToMedia";
import { MWProviderMediaResult } from "providers"; import { MWProviderMediaResult } from "providers";
import { CORS_PROXY_URL } from "mw_constants";
export const theFlixScraper: MWMediaProvider = { export const theFlixScraper: MWMediaProvider = {
id: "theflix", id: "theflix",
@ -43,4 +45,29 @@ export const theFlixScraper: MWMediaProvider = {
return results; return results;
}, },
async getStream(media: MWPortableMedia): Promise<MWMediaStream> {
let url = "";
if (media.mediaType === MWMediaType.MOVIE) {
url = `${CORS_PROXY_URL}https://theflix.to/movie/${media.mediaId}?movieInfo=${media.mediaId}`;
} else if (media.mediaType === MWMediaType.SERIES) {
url = `${CORS_PROXY_URL}https://theflix.to/tv-show/${media.mediaId}/season-${media.season}/episode-${media.episode}`;
}
const res = await fetch(url).then((d) => d.text());
const prop: HTMLElement | undefined = Array.from(
new DOMParser()
.parseFromString(res, "text/html")
.querySelectorAll("script")
).find((e) => e.textContent?.includes("theflixvd.b-cdn"));
if (!prop || !prop.textContent) {
throw new Error("Could not find stream");
}
const data = JSON.parse(prop.textContent);
return { url: data.props.pageProps.videoUrl, type: "mp4" };
},
}; };

View File

@ -12,6 +12,12 @@ export interface MWPortableMedia {
episode?: number; episode?: number;
} }
export type MWMediaStreamType = "m3u8" | "mp4";
export interface MWMediaStream {
url: string;
type: MWMediaStreamType;
}
export interface MWMedia extends MWPortableMedia { export interface MWMedia extends MWPortableMedia {
title: string; title: string;
year: string; year: string;
@ -32,17 +38,18 @@ export interface MWMediaProvider {
getMediaFromPortable(media: MWPortableMedia): Promise<MWProviderMediaResult>; getMediaFromPortable(media: MWPortableMedia): Promise<MWProviderMediaResult>;
searchForMedia(query: MWQuery): Promise<MWProviderMediaResult[]>; searchForMedia(query: MWQuery): Promise<MWProviderMediaResult[]>;
getStream(media: MWPortableMedia): Promise<MWMediaStream>;
} }
export interface MWMassProviderOutput { export interface MWMassProviderOutput {
providers: { providers: {
id: string, id: string;
success: boolean, success: boolean;
}[]; }[];
results: MWMedia[], results: MWMedia[];
stats: { stats: {
total: number, total: number;
failed: number, failed: number;
succeeded: number, succeeded: number;
} };
} }

View File

@ -1,8 +1,9 @@
import { MWMedia, MWMediaProvider, MWPortableMedia, MWQuery } from "./types"; import { MWMedia, MWMediaProvider, MWMediaStream, MWPortableMedia, MWQuery } from "./types";
export interface MWWrappedMediaProvider extends MWMediaProvider { export interface MWWrappedMediaProvider extends MWMediaProvider {
getMediaFromPortable(media: MWPortableMedia): Promise<MWMedia>; getMediaFromPortable(media: MWPortableMedia): Promise<MWMedia>;
searchForMedia(query: MWQuery): Promise<MWMedia[]>; searchForMedia(query: MWQuery): Promise<MWMedia[]>;
getStream(media: MWPortableMedia): Promise<MWMediaStream>;
} }
export function WrapProvider( export function WrapProvider(