mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 18:13:25 +00:00
Basically library structure
This commit is contained in:
@@ -1,4 +1,13 @@
|
||||
import { Fetcher } from '@/utils/fetcher';
|
||||
import { Fetcher } from '@/fetchers/types';
|
||||
import { MetaOutput, getAllEmbedMetaSorted, getAllSourceMetaSorted, getSpecificId } from '@/main/meta';
|
||||
import { EmbedRunOutput, RunOutput, SourceRunOutput } from '@/main/runner';
|
||||
import { getProviders } from '@/providers/all';
|
||||
|
||||
// TODO meta data input (tmdb id, imdb id, title, release year)
|
||||
// TODO actually running scrapers
|
||||
// TODO documentation: examples for nodejs + browser
|
||||
// TODO documentation: how to use + usecases
|
||||
// TODO documentation: examples on how to make a custom fetcher
|
||||
|
||||
export interface ProviderBuilderOptions {
|
||||
// fetcher, every web request gets called through here
|
||||
@@ -9,18 +18,39 @@ export interface ProviderBuilderOptions {
|
||||
proxiedFetcher?: Fetcher;
|
||||
}
|
||||
|
||||
export interface Providers {}
|
||||
export interface ProviderControls {
|
||||
// Run all providers one by one. in order of rank (highest first)
|
||||
// returns the stream, or null if none found
|
||||
runAll(): Promise<RunOutput | null>;
|
||||
|
||||
export function makeProviders(ops: ProviderBuilderOptions): Providers {
|
||||
return {};
|
||||
// Run a source provider
|
||||
runSource(id: string): Promise<SourceRunOutput>;
|
||||
|
||||
// Run a embed provider
|
||||
runEmbed(id: string): Promise<EmbedRunOutput>;
|
||||
|
||||
// get meta data about a source or embed.
|
||||
getMetadata(id: string): MetaOutput | null;
|
||||
|
||||
// return all sources. sorted by rank (highest first)
|
||||
listSources(): MetaOutput[];
|
||||
|
||||
// return all embed scrapers. sorted by rank (highest first)
|
||||
listEmbeds(): MetaOutput[];
|
||||
}
|
||||
|
||||
//
|
||||
export function makeProviders(_ops: ProviderBuilderOptions): ProviderControls {
|
||||
const list = getProviders();
|
||||
|
||||
// const scrapers = makeProviders({
|
||||
// fetcher: makeFetcher(fetch),
|
||||
// });
|
||||
|
||||
// scrapers.scrape();
|
||||
// scrapers.callScraper(id);
|
||||
// scrapers.getScraper(id);
|
||||
return {
|
||||
getMetadata(id) {
|
||||
return getSpecificId(list, id);
|
||||
},
|
||||
listSources() {
|
||||
return getAllSourceMetaSorted(list);
|
||||
},
|
||||
listEmbeds() {
|
||||
return getAllEmbedMetaSorted(list);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
37
src/main/meta.ts
Normal file
37
src/main/meta.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { ProviderList } from '@/providers/all';
|
||||
|
||||
export type MetaOutput = {
|
||||
type: 'embed' | 'source';
|
||||
id: string;
|
||||
rank: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export function getAllSourceMetaSorted(list: ProviderList): MetaOutput[] {
|
||||
return list.sources
|
||||
.sort((a, b) => b.rank - a.rank)
|
||||
.map((v) => ({
|
||||
type: 'source',
|
||||
id: v.id,
|
||||
name: v.name,
|
||||
rank: v.rank,
|
||||
}));
|
||||
}
|
||||
|
||||
export function getAllEmbedMetaSorted(_list: ProviderList): MetaOutput[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
export function getSpecificId(list: ProviderList, id: string): MetaOutput | null {
|
||||
const foundSource = list.sources.find((v) => v.id === id);
|
||||
if (foundSource) {
|
||||
return {
|
||||
type: 'source',
|
||||
id: foundSource.id,
|
||||
name: foundSource.name,
|
||||
rank: foundSource.rank,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
18
src/main/runner.ts
Normal file
18
src/main/runner.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Stream } from '@/providers/streams';
|
||||
|
||||
export type RunOutput = {
|
||||
sourceId: string;
|
||||
fromEmbed: boolean;
|
||||
stream: Stream;
|
||||
};
|
||||
|
||||
export type SourceRunOutput = {
|
||||
sourceId: string;
|
||||
stream?: Stream;
|
||||
embeds: [];
|
||||
};
|
||||
|
||||
export type EmbedRunOutput = {
|
||||
embedId: string;
|
||||
stream?: Stream;
|
||||
};
|
Reference in New Issue
Block a user