mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 12:43:25 +00:00
Refactor type definitions and update function signatures
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { MovieMedia } from '@/main/media';
|
||||||
|
|
||||||
// ! Types
|
// ! Types
|
||||||
interface BaseConfig {
|
interface BaseConfig {
|
||||||
/** The website's slug. Formatted as `1839578-person-of-interest-2011` */
|
/** The website's slug. Formatted as `1839578-person-of-interest-2011` */
|
||||||
@@ -33,15 +35,26 @@ export interface ShowDataResult {
|
|||||||
episodes: episodeObj[];
|
episodes: episodeObj[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StreamsDataResult {
|
interface VideoSources {
|
||||||
streams: any[];
|
[key: string]: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Result {
|
export interface StreamsDataResult {
|
||||||
|
streams: VideoSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResultItem {
|
||||||
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[];
|
}
|
||||||
|
|
||||||
|
export interface Result {
|
||||||
|
title(media: MovieMedia, title: any, arg2: number): boolean;
|
||||||
|
year(year: any): number | undefined;
|
||||||
|
id_movie: any;
|
||||||
|
id_show: string;
|
||||||
|
items: ResultItem[];
|
||||||
}
|
}
|
||||||
|
@@ -3,13 +3,13 @@ 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, ShowDataResult, episodeObj } from './type';
|
import { Result, ResultItem, ShowDataResult, episodeObj } from './type';
|
||||||
import { getVideoUrl } from './video';
|
import { getVideoUrl } from './video';
|
||||||
|
|
||||||
export async function searchAndFindMedia(
|
export async function searchAndFindMedia(
|
||||||
ctx: ScrapeContext,
|
ctx: ScrapeContext,
|
||||||
media: MovieMedia | ShowMedia,
|
media: MovieMedia | ShowMedia,
|
||||||
): Promise<Result | undefined> {
|
): Promise<ResultItem | undefined> {
|
||||||
if (media.type === 'show') {
|
if (media.type === 'show') {
|
||||||
const searchRes = await ctx.fetcher<Result>(`/v1/shows`, {
|
const searchRes = await ctx.fetcher<Result>(`/v1/shows`, {
|
||||||
baseUrl: 'https://lmscript.xyz',
|
baseUrl: 'https://lmscript.xyz',
|
||||||
@@ -18,7 +18,7 @@ export async function searchAndFindMedia(
|
|||||||
|
|
||||||
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: ResultItem) => compareMedia(media, res.title, Number(res.year)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (media.type === 'movie') {
|
if (media.type === 'movie') {
|
||||||
@@ -28,12 +28,12 @@ export async function searchAndFindMedia(
|
|||||||
});
|
});
|
||||||
|
|
||||||
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: ResultItem) => compareMedia(media, res.title, Number(res.year)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function scrape(ctx: ScrapeContext, media: MovieMedia | ShowMedia, result: Result) {
|
export async function scrape(ctx: ScrapeContext, media: MovieMedia | ShowMedia, result: ResultItem) {
|
||||||
// Find the relevant id
|
// Find the relevant id
|
||||||
let id = null;
|
let id = null;
|
||||||
if (media.type === 'movie') {
|
if (media.type === 'movie') {
|
||||||
|
@@ -3,7 +3,11 @@ import { ScrapeContext } from '@/utils/context';
|
|||||||
|
|
||||||
import { StreamsDataResult } from './type';
|
import { StreamsDataResult } from './type';
|
||||||
|
|
||||||
export async function getVideoSources(ctx: ScrapeContext, id: string, media: MovieMedia | ShowMedia): Promise<any> {
|
export async function getVideoSources(
|
||||||
|
ctx: ScrapeContext,
|
||||||
|
id: string,
|
||||||
|
media: MovieMedia | ShowMedia,
|
||||||
|
): Promise<StreamsDataResult> {
|
||||||
// Fetch video sources
|
// Fetch video sources
|
||||||
|
|
||||||
let path = '';
|
let path = '';
|
||||||
|
Reference in New Issue
Block a user