mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 10:33: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
|
||||
interface BaseConfig {
|
||||
/** The website's slug. Formatted as `1839578-person-of-interest-2011` */
|
||||
@@ -33,15 +35,26 @@ export interface ShowDataResult {
|
||||
episodes: episodeObj[];
|
||||
}
|
||||
|
||||
export interface StreamsDataResult {
|
||||
streams: any[];
|
||||
interface VideoSources {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export interface Result {
|
||||
export interface StreamsDataResult {
|
||||
streams: VideoSources;
|
||||
}
|
||||
|
||||
export interface ResultItem {
|
||||
title: string;
|
||||
slug: string;
|
||||
year: string;
|
||||
id_movie: 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 { NotFoundError } from '@/utils/errors';
|
||||
|
||||
import { Result, ShowDataResult, episodeObj } from './type';
|
||||
import { Result, ResultItem, ShowDataResult, episodeObj } from './type';
|
||||
import { getVideoUrl } from './video';
|
||||
|
||||
export async function searchAndFindMedia(
|
||||
ctx: ScrapeContext,
|
||||
media: MovieMedia | ShowMedia,
|
||||
): Promise<Result | undefined> {
|
||||
): Promise<ResultItem | undefined> {
|
||||
if (media.type === 'show') {
|
||||
const searchRes = await ctx.fetcher<Result>(`/v1/shows`, {
|
||||
baseUrl: 'https://lmscript.xyz',
|
||||
@@ -18,7 +18,7 @@ export async function searchAndFindMedia(
|
||||
|
||||
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;
|
||||
}
|
||||
if (media.type === 'movie') {
|
||||
@@ -28,12 +28,12 @@ export async function searchAndFindMedia(
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
let id = null;
|
||||
if (media.type === 'movie') {
|
||||
|
@@ -3,7 +3,11 @@ import { ScrapeContext } from '@/utils/context';
|
||||
|
||||
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
|
||||
|
||||
let path = '';
|
||||
|
Reference in New Issue
Block a user