mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 16:53:24 +00:00
Move runScraper to use the options instead of providers itself
This commit is contained in:
@@ -9,7 +9,7 @@ import { logDeepObject } from '@/dev-cli/logging';
|
|||||||
import { getMovieMediaDetails, getShowMediaDetails } from '@/dev-cli/tmdb';
|
import { getMovieMediaDetails, getShowMediaDetails } from '@/dev-cli/tmdb';
|
||||||
import { CommandLineArguments, processOptions } from '@/dev-cli/validate';
|
import { CommandLineArguments, processOptions } from '@/dev-cli/validate';
|
||||||
|
|
||||||
import { MetaOutput, ProviderControls, getBuiltinEmbeds, getBuiltinSources } from '..';
|
import { MetaOutput, ProviderMakerOptions, getBuiltinEmbeds, getBuiltinSources, makeProviders } from '..';
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@@ -49,8 +49,9 @@ function joinMediaTypes(mediaTypes: string[] | undefined) {
|
|||||||
return ''; // * Embed sources pass through here too
|
return ''; // * Embed sources pass through here too
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runScraper(providers: ProviderControls, source: MetaOutput, options: CommandLineArguments) {
|
async function runScraper(providerOptions: ProviderMakerOptions, source: MetaOutput, options: CommandLineArguments) {
|
||||||
const spinnies = new Spinnies();
|
const spinnies = new Spinnies();
|
||||||
|
const providers = makeProviders(providerOptions);
|
||||||
|
|
||||||
if (source.type === 'embed') {
|
if (source.type === 'embed') {
|
||||||
spinnies.add('scrape', { text: `Running ${source.name} scraper on ${options.url}` });
|
spinnies.add('scrape', { text: `Running ${source.name} scraper on ${options.url}` });
|
||||||
@@ -200,8 +201,8 @@ async function runQuestions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { providers, source: validatedSource, options: validatedOps } = await processOptions(sources, options);
|
const { providerOptions, source: validatedSource, options: validatedOps } = await processOptions(sources, options);
|
||||||
await runScraper(providers, validatedSource, validatedOps);
|
await runScraper(providerOptions, validatedSource, validatedOps);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runCommandLine() {
|
async function runCommandLine() {
|
||||||
@@ -216,8 +217,12 @@ async function runCommandLine() {
|
|||||||
|
|
||||||
program.parse();
|
program.parse();
|
||||||
|
|
||||||
const { providers, source: validatedSource, options: validatedOps } = await processOptions(sources, program.opts());
|
const {
|
||||||
await runScraper(providers, validatedSource, validatedOps);
|
providerOptions,
|
||||||
|
source: validatedSource,
|
||||||
|
options: validatedOps,
|
||||||
|
} = await processOptions(sources, program.opts());
|
||||||
|
await runScraper(providerOptions, validatedSource, validatedOps);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv.length === 2) {
|
if (process.argv.length === 2) {
|
||||||
|
@@ -2,7 +2,7 @@ import nodeFetch from 'node-fetch';
|
|||||||
|
|
||||||
import { Embed, Sourcerer } from '@/providers/base';
|
import { Embed, Sourcerer } from '@/providers/base';
|
||||||
|
|
||||||
import { makeProviders, makeStandardFetcher, targets } from '..';
|
import { ProviderMakerOptions, makeStandardFetcher, targets } from '..';
|
||||||
|
|
||||||
export type CommandLineArguments = {
|
export type CommandLineArguments = {
|
||||||
fetcher: string;
|
fetcher: string;
|
||||||
@@ -15,8 +15,9 @@ export type CommandLineArguments = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function processOptions(sources: Array<Embed | Sourcerer>, options: CommandLineArguments) {
|
export async function processOptions(sources: Array<Embed | Sourcerer>, options: CommandLineArguments) {
|
||||||
if (options.fetcher !== 'node-fetch' && options.fetcher !== 'native') {
|
const fetcherOptions = ['node-fetch', 'native', 'browser'];
|
||||||
throw new Error("Fetcher must be either 'native' or 'node-fetch'");
|
if (!fetcherOptions.includes(options.fetcher)) {
|
||||||
|
throw new Error(`Fetcher must be any of: ${fetcherOptions.join()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.sourceId.trim()) {
|
if (!options.sourceId.trim()) {
|
||||||
@@ -77,13 +78,13 @@ export async function processOptions(sources: Array<Embed | Sourcerer>, options:
|
|||||||
fetcher = makeStandardFetcher(nodeFetch);
|
fetcher = makeStandardFetcher(nodeFetch);
|
||||||
}
|
}
|
||||||
|
|
||||||
const providers = makeProviders({
|
const providerOptions: ProviderMakerOptions = {
|
||||||
fetcher,
|
fetcher,
|
||||||
target: targets.NATIVE,
|
target: targets.ANY,
|
||||||
});
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
providers,
|
providerOptions,
|
||||||
options,
|
options,
|
||||||
source,
|
source,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user