individual provider runs

This commit is contained in:
mrjvs
2023-09-06 21:24:39 +02:00
parent 493032590e
commit 7b9b25acab
5 changed files with 72 additions and 13 deletions

View File

@@ -1,8 +1,15 @@
export type { EmbedOutput, SourcererOutput } from '@/providers/base';
export type { RunOutput } from '@/main/runner';
export type { MetaOutput } from '@/main/meta';
export type { FullScraperEvents } from '@/main/events';
export type { MediaTypes, ShowMedia, ScrapeMedia, MovieMedia } from '@/main/media';
export type { ProviderBuilderOptions, ProviderControls, RunnerOptions } from '@/main/builder';
export type {
ProviderBuilderOptions,
ProviderControls,
RunnerOptions,
EmbedRunnerOptions,
SourceRunnerOptions,
} from '@/main/builder';
export { NotFoundError } from '@/utils/errors';
export { makeProviders } from '@/main/builder';

View File

@@ -1,9 +1,11 @@
import { makeFullFetcher } from '@/fetchers/common';
import { Fetcher } from '@/fetchers/types';
import { FullScraperEvents } from '@/main/events';
import { FullScraperEvents, IndividualScraperEvents } from '@/main/events';
import { scrapeIndividualEmbed, scrapeInvidualSource } from '@/main/individualRunner';
import { ScrapeMedia } from '@/main/media';
import { MetaOutput, getAllEmbedMetaSorted, getAllSourceMetaSorted, getSpecificId } from '@/main/meta';
import { RunOutput, runAllProviders } from '@/main/runner';
import { EmbedOutput, SourcererOutput } from '@/providers/base';
import { getProviders } from '@/providers/get';
export interface ProviderBuilderOptions {
@@ -31,11 +33,39 @@ export interface RunnerOptions {
media: ScrapeMedia;
}
export interface SourceRunnerOptions {
// object of event functions
events?: IndividualScraperEvents;
// the media you want to see sources from
media: ScrapeMedia;
// id of the source scraper you want to scrape from
id: string;
}
export interface EmbedRunnerOptions {
// object of event functions
events?: IndividualScraperEvents;
// the embed url
url: string;
// id of the embed scraper you want to scrape from
id: string;
}
export interface ProviderControls {
// Run all providers one by one. in order of rank (highest first)
// returns the stream, or null if none found
runAll(runnerOps: RunnerOptions): Promise<RunOutput | null>;
// Run a specific source scraper
runSourceScraper(runnerOps: SourceRunnerOptions): Promise<SourcererOutput>;
// Run a specific embed scraper
runEmbedScraper(runnerOps: EmbedRunnerOptions): Promise<EmbedOutput>;
// get meta data about a source or embed.
getMetadata(id: string): MetaOutput | null;
@@ -54,12 +84,24 @@ export function makeProviders(ops: ProviderBuilderOptions): ProviderControls {
};
return {
runAll(runnerOps: RunnerOptions) {
runAll(runnerOps) {
return runAllProviders(list, {
...providerRunnerOps,
...runnerOps,
});
},
runSourceScraper(runnerOps) {
return scrapeInvidualSource(list, {
...providerRunnerOps,
...runnerOps,
});
},
runEmbedScraper(runnerOps) {
return scrapeIndividualEmbed(list, {
...providerRunnerOps,
...runnerOps,
});
},
getMetadata(id) {
return getSpecificId(list, id);
},

View File

@@ -46,3 +46,8 @@ export type FullScraperEvents = {
// start scraping an item.
start?: (id: string) => void;
};
export type IndividualScraperEvents = {
// update progress percentage and status of the currently scraping item
update?: (evt: UpdateEvent) => void;
};

View File

@@ -1,5 +1,5 @@
import { UseableFetcher } from '@/fetchers/types';
import { UpdateEvent } from '@/main/events';
import { IndividualScraperEvents } from '@/main/events';
import { ScrapeMedia } from '@/main/media';
import { EmbedOutput, SourcererOutput } from '@/providers/base';
import { ProviderList } from '@/providers/get';
@@ -10,9 +10,7 @@ export type IndividualSourceRunnerOptions = {
proxiedFetcher: UseableFetcher;
media: ScrapeMedia;
id: string;
events: {
update?: (evt: UpdateEvent) => void;
};
events?: IndividualScraperEvents;
};
export async function scrapeInvidualSource(
@@ -56,9 +54,7 @@ export type IndividualEmbedRunnerOptions = {
proxiedFetcher: UseableFetcher;
url: string;
id: string;
events?: {
update?: (evt: UpdateEvent) => void;
};
events?: IndividualScraperEvents;
};
export async function scrapeIndividualEmbed(