mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 18:13:25 +00:00
Seperate scraper code from index cli file
This commit is contained in:
@@ -3,13 +3,11 @@
|
||||
import { program } from 'commander';
|
||||
import dotenv from 'dotenv';
|
||||
import { prompt } from 'enquirer';
|
||||
import Spinnies from 'spinnies';
|
||||
|
||||
import { logDeepObject } from '@/dev-cli/logging';
|
||||
import { getMovieMediaDetails, getShowMediaDetails } from '@/dev-cli/tmdb';
|
||||
import { CommandLineArguments, processOptions } from '@/dev-cli/validate';
|
||||
import { runScraper } from '@/dev-cli/scraper';
|
||||
import { processOptions } from '@/dev-cli/validate';
|
||||
|
||||
import { MetaOutput, ProviderMakerOptions, getBuiltinEmbeds, getBuiltinSources, makeProviders } from '..';
|
||||
import { getBuiltinEmbeds, getBuiltinSources } from '..';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
@@ -49,55 +47,6 @@ function joinMediaTypes(mediaTypes: string[] | undefined) {
|
||||
return ''; // * Embed sources pass through here too
|
||||
}
|
||||
|
||||
async function runScraper(providerOptions: ProviderMakerOptions, source: MetaOutput, options: CommandLineArguments) {
|
||||
const spinnies = new Spinnies();
|
||||
const providers = makeProviders(providerOptions);
|
||||
|
||||
if (source.type === 'embed') {
|
||||
spinnies.add('scrape', { text: `Running ${source.name} scraper on ${options.url}` });
|
||||
try {
|
||||
const result = await providers.runEmbedScraper({
|
||||
url: options.url,
|
||||
id: source.id,
|
||||
});
|
||||
spinnies.succeed('scrape', { text: 'Done!' });
|
||||
logDeepObject(result);
|
||||
} catch (error) {
|
||||
let message = 'Unknown error';
|
||||
if (error instanceof Error) {
|
||||
message = error.message;
|
||||
}
|
||||
|
||||
spinnies.fail('scrape', { text: `ERROR: ${message}` });
|
||||
}
|
||||
} else {
|
||||
let media;
|
||||
|
||||
if (options.type === 'movie') {
|
||||
media = await getMovieMediaDetails(options.tmdbId);
|
||||
} else {
|
||||
media = await getShowMediaDetails(options.tmdbId, options.season, options.episode);
|
||||
}
|
||||
|
||||
spinnies.add('scrape', { text: `Running ${source.name} scraper on ${media.title}` });
|
||||
try {
|
||||
const result = await providers.runSourceScraper({
|
||||
media,
|
||||
id: source.id,
|
||||
});
|
||||
spinnies.succeed('scrape', { text: 'Done!' });
|
||||
logDeepObject(result);
|
||||
} catch (error) {
|
||||
let message = 'Unknown error';
|
||||
if (error instanceof Error) {
|
||||
message = error.message;
|
||||
}
|
||||
|
||||
spinnies.fail('scrape', { text: `ERROR: ${message}` });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function runQuestions() {
|
||||
const options = {
|
||||
fetcher: 'node-fetch',
|
||||
|
Reference in New Issue
Block a user