mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 18:13:25 +00:00
All the Changes Requested Complete
This commit is contained in:
4409
package-lock.json
generated
4409
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
3535
pnpm-lock.yaml
generated
3535
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -5,11 +5,11 @@ import { scrape, searchAndFindMedia } from './util';
|
|||||||
import { MovieContext, ShowContext } from '../zoechip/common';
|
import { MovieContext, ShowContext } from '../zoechip/common';
|
||||||
|
|
||||||
async function universalScraper(ctx: ShowContext | MovieContext): Promise<SourcererOutput> {
|
async function universalScraper(ctx: ShowContext | MovieContext): Promise<SourcererOutput> {
|
||||||
const lookmovieData = await searchAndFindMedia(ctx.media);
|
const lookmovieData = await searchAndFindMedia(ctx, ctx.media);
|
||||||
if (!lookmovieData) throw new NotFoundError('Media not found');
|
if (!lookmovieData) throw new NotFoundError('Media not found');
|
||||||
|
|
||||||
ctx.progress(30);
|
ctx.progress(30);
|
||||||
const videoUrl = await scrape(ctx.media, lookmovieData);
|
const videoUrl = await scrape(ctx, ctx.media, lookmovieData);
|
||||||
if (!videoUrl) throw new NotFoundError('No video found');
|
if (!videoUrl) throw new NotFoundError('No video found');
|
||||||
|
|
||||||
ctx.progress(60);
|
ctx.progress(60);
|
||||||
|
@@ -1,52 +1,56 @@
|
|||||||
import json5 from 'json5';
|
|
||||||
|
|
||||||
import { MovieMedia, ShowMedia } from '@/main/media';
|
import { MovieMedia, ShowMedia } from '@/main/media';
|
||||||
import { compareMedia } from '@/utils/compare';
|
import { compareMedia } from '@/utils/compare';
|
||||||
|
import { ScrapeContext } from '@/utils/context';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
|
|
||||||
import { Result } from './type';
|
import { Result } from './type';
|
||||||
import { getVideoUrl } from './video';
|
import { getVideoUrl } from './video';
|
||||||
|
|
||||||
export async function searchAndFindMedia(media: MovieMedia | ShowMedia): Promise<Result | undefined> {
|
export async function searchAndFindMedia(
|
||||||
if (media.type === "show") {
|
ctx: ScrapeContext,
|
||||||
const searchRes = await fetch(`https://lmscript.xyz/v1/shows?filters[q]=${encodeURIComponent(media.title)}`).then((d) => d.json());
|
media: MovieMedia | ShowMedia,
|
||||||
|
): Promise<Result | undefined> {
|
||||||
|
if (media.type === 'show') {
|
||||||
|
const searchRes = await ctx.fetcher<any>(`/v1/shows?filters[q]=${media.title}`, {
|
||||||
|
baseUrl: 'https://lmscript.xyz',
|
||||||
|
});
|
||||||
|
|
||||||
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;
|
||||||
} else if (media.type === "movie") {
|
}
|
||||||
const searchRes = await fetch(`https://lmscript.xyz/v1/movies?filters[q]=${encodeURIComponent(media.title)}`).then((d) => d.json());
|
if (media.type === 'movie') {
|
||||||
|
const searchRes = await ctx.fetcher<any>(`/v1/movies?filters[q]=${media.title}`, {
|
||||||
|
baseUrl: 'https://lmscript.xyz',
|
||||||
|
});
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function scrape(media: MovieMedia | ShowMedia, result: Result) {
|
export async function scrape(ctx: ScrapeContext, media: MovieMedia | ShowMedia, result: Result) {
|
||||||
// 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 data = await fetch(`https://lmscript.xyz/v1/shows?expand=episodes&id=${result.id_show}`).then((d) => d.json());
|
const data: any = await ctx
|
||||||
|
.fetcher<any>(`https://lmscript.xyz/v1/shows?expand=episodes&id=${result.id_show}`)
|
||||||
|
.then((d) => d);
|
||||||
|
|
||||||
const episodeObj = data.episodes?.find((v: any) => {
|
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;
|
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');
|
||||||
|
|
||||||
|
const videoUrl = await getVideoUrl(ctx, id, media);
|
||||||
const videoUrl = await getVideoUrl(id,media);
|
|
||||||
return videoUrl;
|
return videoUrl;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { Config } from './type';
|
|
||||||
import { MovieMedia, ShowMedia } from '@/main/media';
|
import { MovieMedia, ShowMedia } from '@/main/media';
|
||||||
|
import { ScrapeContext } from '@/utils/context';
|
||||||
|
|
||||||
export async function getVideoSources(id:any,media: MovieMedia | ShowMedia): Promise<any> {
|
export async function getVideoSources(ctx: ScrapeContext, id: any, media: MovieMedia | ShowMedia): Promise<any> {
|
||||||
// Fetch video sources
|
// Fetch video sources
|
||||||
|
|
||||||
let url = '';
|
let url = '';
|
||||||
@@ -10,17 +10,17 @@ export async function getVideoSources(id:any,media: MovieMedia | ShowMedia): Pro
|
|||||||
} else if (media.type === 'movie') {
|
} else if (media.type === 'movie') {
|
||||||
url = `https://lmscript.xyz/v1/movies/view?expand=streams&id=${id}`;
|
url = `https://lmscript.xyz/v1/movies/view?expand=streams&id=${id}`;
|
||||||
}
|
}
|
||||||
const data = await fetch(url).then((d) => d.json());
|
const data = await ctx.fetcher<any>(url).then((d) => d);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getVideoUrl(id:any,media: MovieMedia | ShowMedia): Promise<string | null> {
|
export async function getVideoUrl(ctx: ScrapeContext, id: any, media: MovieMedia | ShowMedia): Promise<string | null> {
|
||||||
// Get sources
|
// Get sources
|
||||||
const data = await getVideoSources(id,media);
|
const data = await getVideoSources(ctx, 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','240p','240','360p','360',"144","144p", 'auto'];
|
const opts = ['auto', '1080p', '1080', '720p', '720', '480p', '480', '240p', '240', '360p', '360', '144', '144p'];
|
||||||
|
|
||||||
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