mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 12:43:25 +00:00
Finished Lookmovie Scraper
This commit is contained in:
@@ -28,4 +28,5 @@ export interface Result {
|
|||||||
slug: string;
|
slug: string;
|
||||||
year: string;
|
year: string;
|
||||||
id_movie?: string;
|
id_movie?: string;
|
||||||
|
id_show?: string;
|
||||||
}
|
}
|
||||||
|
@@ -11,12 +11,13 @@ export async function searchAndFindMedia(media: MovieMedia | ShowMedia): Promise
|
|||||||
if (media.type === "show") {
|
if (media.type === "show") {
|
||||||
const searchRes = await fetch(`https://lmscript.xyz/v1/shows?filters[q]=${encodeURIComponent(media.title)}`).then((d) => d.json());
|
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)));
|
const result = results.find((res: Result) => compareMedia(media, res.title, Number(res.year)));
|
||||||
return result;
|
return result;
|
||||||
} else if (media.type === "movie") {
|
} else if (media.type === "movie") {
|
||||||
const searchRes = await fetch(`https://lmscript.xyz/v1/movies?filters[q]=${encodeURIComponent(media.title)}`).then((d) => d.json());
|
const searchRes = await fetch(`https://lmscript.xyz/v1/movies?filters[q]=${encodeURIComponent(media.title)}`).then((d) => d.json());
|
||||||
|
|
||||||
const results = searchRes.items;
|
const results = searchRes.items;
|
||||||
const result = results.find((res: Result) => compareMedia(media, res.title, Number(res.year)));
|
const result = results.find((res: Result) => compareMedia(media, res.title, Number(res.year)));
|
||||||
return result;
|
return result;
|
||||||
@@ -26,52 +27,26 @@ export async function searchAndFindMedia(media: MovieMedia | ShowMedia): Promise
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function scrape(media: MovieMedia | ShowMedia, result: Result) {
|
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
|
// Find the relevant id
|
||||||
let id = null;
|
let id = null;
|
||||||
if (media.type === 'movie') {
|
if (media.type === 'movie') {
|
||||||
id = result.id_movie;
|
id = result.id_movie;
|
||||||
} else if (media.type === 'show') {
|
} 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);
|
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
|
// Check ID
|
||||||
if (id === null) throw new NotFoundError('Not found');
|
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(id,media);
|
||||||
|
|
||||||
const videoUrl = await getVideoUrl(reqObj);
|
|
||||||
return videoUrl;
|
return videoUrl;
|
||||||
}
|
}
|
||||||
|
@@ -1,24 +1,26 @@
|
|||||||
import { Config } from './type';
|
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
|
// Fetch video sources
|
||||||
|
|
||||||
let url = '';
|
let url = '';
|
||||||
if (config.type === 'show') {
|
if (media.type === 'show') {
|
||||||
url = `https://www.lookmovie2.to/api/v1/security/episode-access?id_episode=${config.episodeId}&hash=${config.hash}&expires=${config.expires}`;
|
url = `https://lmscript.xyz/v1/episodes/view?expand=streams&id=${id}`;
|
||||||
} else if (config.type === 'movie') {
|
} else if (media.type === 'movie') {
|
||||||
url = `https://www.lookmovie2.to/api/v1/security/movie-access?id_movie=${config.id_movie}&hash=${config.hash}&expires=${config.expires}`;
|
url = `https://lmscript.xyz/v1/movies/view?expand=streams&id=${id}`;
|
||||||
}
|
}
|
||||||
const data = await fetch(url).then((d) => d.json());
|
const data = await fetch(url).then((d) => d.json());
|
||||||
return data;
|
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
|
// Get sources
|
||||||
const data = await getVideoSources(config);
|
const data = await getVideoSources(id,media);
|
||||||
const videoSources = data.streams;
|
const videoSources = data.streams;
|
||||||
|
|
||||||
// Find video URL and return it
|
// 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;
|
let videoUrl: string | null = null;
|
||||||
for (const res of opts) {
|
for (const res of opts) {
|
||||||
|
Reference in New Issue
Block a user