providers/.docs/content/5.api-reference/2.ProviderControlsrunSource...

67 lines
1.3 KiB
Markdown
Raw Normal View History

2023-09-27 17:00:40 +00:00
# `ProviderControls.runSourceScraper`
Run a specific source scraper and get its outputted streams.
## Example
```ts
2023-12-29 16:47:49 +00:00
import { SourcererOutput, NotFoundError } from '@movie-web/providers';
2023-09-27 17:00:40 +00:00
// media from TMDB
const media = {
type: 'movie',
2023-12-29 16:47:49 +00:00
title: 'Hamilton',
2023-09-27 17:00:40 +00:00
releaseYear: 2020,
2023-12-29 16:47:49 +00:00
tmdbId: '556574'
2023-09-27 17:00:40 +00:00
}
// scrape a stream from flixhq
let output: SourcererOutput;
try {
output = await providers.runSourceScraper({
id: 'flixhq',
media: media,
})
} catch (err) {
if (err instanceof NotFoundError) {
2023-12-29 16:47:49 +00:00
console.log('source doesnt have this media');
2023-09-27 17:00:40 +00:00
} else {
2023-12-29 16:47:49 +00:00
console.log('failed to scrape')
2023-09-27 17:00:40 +00:00
}
return;
}
if (!output.stream && output.embeds.length === 0) {
2023-12-29 16:47:49 +00:00
console.log('no streams found');
2023-09-27 17:00:40 +00:00
}
```
## Type
```ts
function runSourceScraper(runnerOps: SourceRunnerOptions): Promise<SourcererOutput>;
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;
}
type SourcererOutput = {
// list of embeds that the source scraper found.
// embed id is a reference to an embed scraper
embeds: {
embedId: string;
url: string;
}[];
// the stream that the scraper found
stream?: Stream;
};
```