Added IP_LOCKED flag amonst other things requested by mrjvs

This commit is contained in:
MemeCornucopia
2023-12-14 12:40:01 -05:00
parent f3720161ac
commit 671c558c55
7 changed files with 45 additions and 17 deletions

7
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "@movie-web/providers", "name": "@movie-web/providers",
"version": "1.1.2", "version": "1.1.4",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@movie-web/providers", "name": "@movie-web/providers",
"version": "1.1.2", "version": "1.1.4",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
@@ -3040,7 +3040,8 @@
}, },
"node_modules/json5": { "node_modules/json5": {
"version": "2.2.3", "version": "2.2.3",
"license": "MIT", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
"bin": { "bin": {
"json5": "lib/cli.js" "json5": "lib/cli.js"
}, },

View File

@@ -79,8 +79,8 @@
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"json5": "^2.2.3",
"iso-639-1": "^3.1.0", "iso-639-1": "^3.1.0",
"json5": "^2.2.3",
"nanoid": "^3.3.6", "nanoid": "^3.3.6",
"node-fetch": "^2.7.0", "node-fetch": "^2.7.0",
"unpacker": "^1.0.1" "unpacker": "^1.0.1"

View File

@@ -1,5 +1,6 @@
export const flags = { export const flags = {
NO_CORS: 'no-cors', NO_CORS: 'no-cors',
IP_LOCKED: 'ip-locked',
} as const; } as const;
export type Flags = (typeof flags)[keyof typeof flags]; export type Flags = (typeof flags)[keyof typeof flags];

View File

@@ -1,3 +1,4 @@
import { flags } from '@/main/targets';
import { SourcererOutput, makeSourcerer } from '@/providers/base'; import { SourcererOutput, makeSourcerer } from '@/providers/base';
import { NotFoundError } from '@/utils/errors'; import { NotFoundError } from '@/utils/errors';
@@ -19,7 +20,7 @@ async function universalScraper(ctx: ShowContext | MovieContext): Promise<Source
stream: { stream: {
playlist: videoUrl, playlist: videoUrl,
type: 'hls', type: 'hls',
flags: [], flags: [flags.IP_LOCKED],
captions: [], captions: [],
}, },
}; };

View File

@@ -23,10 +23,25 @@ interface MovieConfig extends BaseConfig {
} }
export type Config = MovieConfig | TvConfig; export type Config = MovieConfig | TvConfig;
export interface episodeObj {
season: string;
episode: string;
id: string;
}
export interface ShowDataResult {
episodes: episodeObj[];
}
export interface StreamsDataResult {
streams: any[];
}
export interface Result { export interface Result {
title: string; title: string;
slug: string; slug: string;
year: string; year: string;
id_movie?: string; id_movie: string;
id_show?: string; id_show: string;
items: any[];
} }

View File

@@ -3,7 +3,7 @@ import { compareMedia } from '@/utils/compare';
import { ScrapeContext } from '@/utils/context'; import { ScrapeContext } from '@/utils/context';
import { NotFoundError } from '@/utils/errors'; import { NotFoundError } from '@/utils/errors';
import { Result } from './type'; import { Result, ShowDataResult, episodeObj } from './type';
import { getVideoUrl } from './video'; import { getVideoUrl } from './video';
export async function searchAndFindMedia( export async function searchAndFindMedia(
@@ -11,8 +11,9 @@ export async function searchAndFindMedia(
media: MovieMedia | ShowMedia, media: MovieMedia | ShowMedia,
): Promise<Result | undefined> { ): Promise<Result | undefined> {
if (media.type === 'show') { if (media.type === 'show') {
const searchRes = await ctx.fetcher<any>(`/v1/shows?filters[q]=${media.title}`, { const searchRes = await ctx.fetcher<Result>(`/v1/shows`, {
baseUrl: 'https://lmscript.xyz', baseUrl: 'https://lmscript.xyz',
query: { 'filters[q]': media.title },
}); });
const results = searchRes.items; const results = searchRes.items;
@@ -21,8 +22,9 @@ export async function searchAndFindMedia(
return result; return result;
} }
if (media.type === 'movie') { if (media.type === 'movie') {
const searchRes = await ctx.fetcher<any>(`/v1/movies?filters[q]=${media.title}`, { const searchRes = await ctx.fetcher<Result>(`/v1/movies`, {
baseUrl: 'https://lmscript.xyz', baseUrl: 'https://lmscript.xyz',
query: { 'filters[q]': media.title },
}); });
const results = searchRes.items; const results = searchRes.items;
@@ -37,15 +39,16 @@ export async function scrape(ctx: ScrapeContext, media: MovieMedia | ShowMedia,
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 ctx.fetcher<any>(`/v1/shows?expand=episodes&id=${result.id_show}`, { const data = await ctx.fetcher<ShowDataResult>(`/v1/shows`, {
baseUrl: 'https://lmscript.xyz', baseUrl: 'https://lmscript.xyz',
query: { expand: 'episodes', id: result.id_show },
}); });
const episodeObj = data.episodes?.find((v: any) => { const episode = data.episodes?.find((v: episodeObj) => {
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 (episode) id = episode.id;
} }
// Check ID // Check ID

View File

@@ -1,22 +1,29 @@
import { MovieMedia, ShowMedia } from '@/main/media'; import { MovieMedia, ShowMedia } from '@/main/media';
import { ScrapeContext } from '@/utils/context'; import { ScrapeContext } from '@/utils/context';
import { StreamsDataResult } from './type';
export async function getVideoSources(ctx: ScrapeContext, 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 path = ''; let path = '';
if (media.type === 'show') { if (media.type === 'show') {
path = `/v1/episodes/view?expand=streams&id=${id}`; path = `/v1/episodes/view`;
} else if (media.type === 'movie') { } else if (media.type === 'movie') {
path = `/v1/movies/view?expand=streams&id=${id}`; path = `/v1/movies/view`;
} }
const data = await ctx.fetcher<any>(path, { const data = await ctx.fetcher<StreamsDataResult>(path, {
baseUrl: 'https://lmscript.xyz', baseUrl: 'https://lmscript.xyz',
query: { expand: 'streams', id },
}); });
return data; return data;
} }
export async function getVideoUrl(ctx: ScrapeContext, id: any, media: MovieMedia | ShowMedia): Promise<string | null> { export async function getVideoUrl(
ctx: ScrapeContext,
id: string,
media: MovieMedia | ShowMedia,
): Promise<string | null> {
// Get sources // Get sources
const data = await getVideoSources(ctx, id, media); const data = await getVideoSources(ctx, id, media);
const videoSources = data.streams; const videoSources = data.streams;