Finished Lookmovie Scraper
This commit is contained in:
parent
e962bb410f
commit
283b569b7c
|
@ -28,4 +28,5 @@ export interface Result {
|
|||
slug: string;
|
||||
year: string;
|
||||
id_movie?: string;
|
||||
id_show?: string;
|
||||
}
|
||||
|
|
|
@ -11,12 +11,13 @@ export async function searchAndFindMedia(media: MovieMedia | ShowMedia): Promise
|
|||
if (media.type === "show") {
|
||||
const searchRes = await fetch(`https://lmscript.xyz/v1/shows?filters[q]=${encodeURIComponent(media.title)}`).then((d) => d.json());
|
||||
|
||||
const results = searchRes.result;
|
||||
const results = searchRes.items;
|
||||
|
||||
const result = results.find((res: Result) => compareMedia(media, res.title, Number(res.year)));
|
||||
return result;
|
||||
} else if (media.type === "movie") {
|
||||
const searchRes = await fetch(`https://lmscript.xyz/v1/movies?filters[q]=${encodeURIComponent(media.title)}`).then((d) => d.json());
|
||||
|
||||
|
||||
const results = searchRes.items;
|
||||
const result = results.find((res: Result) => compareMedia(media, res.title, Number(res.year)));
|
||||
return result;
|
||||
|
@ -26,52 +27,26 @@ export async function searchAndFindMedia(media: MovieMedia | ShowMedia): Promise
|
|||
}
|
||||
|
||||
export async function scrape(media: MovieMedia | ShowMedia, result: Result) {
|
||||
const url = `https://www.lookmovie2.to/${media.type}s/play/${result.slug}`;
|
||||
const pageReq = await fetch(url).then((d) => d.text());
|
||||
|
||||
// Extract and parse JSON
|
||||
const scriptJson = `{${pageReq
|
||||
.slice(pageReq.indexOf(`${media.type}_storage`))
|
||||
.split('};')[0]
|
||||
.split('= {')[1]
|
||||
.trim()}}`;
|
||||
const data = json5.parse(scriptJson);
|
||||
|
||||
// Find the relevant id
|
||||
let id = null;
|
||||
if (media.type === 'movie') {
|
||||
id = result.id_movie;
|
||||
} else if (media.type === 'show') {
|
||||
const episodeObj = data.seasons.find((v: any) => {
|
||||
const data = await fetch(`https://lmscript.xyz/v1/shows?expand=episodes&id=${result.id_show}`).then((d) => d.json());
|
||||
|
||||
const episodeObj = data.episodes?.find((v: any) => {
|
||||
return Number(v.season) === Number(media.season.number) && Number(v.episode) === Number(media.episode.number);
|
||||
});
|
||||
|
||||
if (episodeObj) id = episodeObj.id_episode;
|
||||
if (episodeObj) id = episodeObj.id;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Check ID
|
||||
if (id === null) throw new NotFoundError('Not found');
|
||||
|
||||
// Generate object to send over to scraper
|
||||
let reqObj = null;
|
||||
if (media.type === 'show') {
|
||||
reqObj = {
|
||||
slug: result.slug,
|
||||
episodeId: id,
|
||||
type: 'tv',
|
||||
...data,
|
||||
};
|
||||
} else if (media.type === 'movie') {
|
||||
reqObj = {
|
||||
slug: result.slug,
|
||||
movieId: id,
|
||||
type: 'movie',
|
||||
...data,
|
||||
};
|
||||
}
|
||||
|
||||
if (!reqObj) throw new NotFoundError('Invalid media type');
|
||||
|
||||
const videoUrl = await getVideoUrl(reqObj);
|
||||
const videoUrl = await getVideoUrl(id,media);
|
||||
return videoUrl;
|
||||
}
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
import { Config } from './type';
|
||||
import { MovieMedia, ShowMedia } from '@/main/media';
|
||||
|
||||
export async function getVideoSources(config: Config): Promise<any> {
|
||||
export async function getVideoSources(id:any,media: MovieMedia | ShowMedia): Promise<any> {
|
||||
// Fetch video sources
|
||||
|
||||
let url = '';
|
||||
if (config.type === 'show') {
|
||||
url = `https://www.lookmovie2.to/api/v1/security/episode-access?id_episode=${config.episodeId}&hash=${config.hash}&expires=${config.expires}`;
|
||||
} else if (config.type === 'movie') {
|
||||
url = `https://www.lookmovie2.to/api/v1/security/movie-access?id_movie=${config.id_movie}&hash=${config.hash}&expires=${config.expires}`;
|
||||
if (media.type === 'show') {
|
||||
url = `https://lmscript.xyz/v1/episodes/view?expand=streams&id=${id}`;
|
||||
} else if (media.type === 'movie') {
|
||||
url = `https://lmscript.xyz/v1/movies/view?expand=streams&id=${id}`;
|
||||
}
|
||||
const data = await fetch(url).then((d) => d.json());
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getVideoUrl(config: Config): Promise<string | null> {
|
||||
export async function getVideoUrl(id:any,media: MovieMedia | ShowMedia): Promise<string | null> {
|
||||
// Get sources
|
||||
const data = await getVideoSources(config);
|
||||
const data = await getVideoSources(id,media);
|
||||
const videoSources = data.streams;
|
||||
|
||||
// Find video URL and return it
|
||||
const opts = ['1080p', '1080', '720p', '720', '480p', '480', 'auto'];
|
||||
const opts = ['1080p', '1080', '720p', '720', '480p', '480','240p','240','360p','360',"144","144p", 'auto'];
|
||||
|
||||
let videoUrl: string | null = null;
|
||||
for (const res of opts) {
|
||||
|
|
Loading…
Reference in New Issue