mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 18:13:25 +00:00
switched to guider
This commit is contained in:
63
.docs/pages/api-reference/ProviderControlsRunAll.md
Normal file
63
.docs/pages/api-reference/ProviderControlsRunAll.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# `ProviderControls.runAll`
|
||||
|
||||
Run all providers one by one in order of their built-in ranking.
|
||||
You can attach events if you need to know what is going on while it is processing.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { ScrapeMedia, targets } from '@movie-web/providers';
|
||||
|
||||
// media from TMDB
|
||||
const media : ScrapeMedia = {
|
||||
type: 'movie',
|
||||
title: 'Hamilton',
|
||||
releaseYear: 2020,
|
||||
tmdbId: '556574'
|
||||
}
|
||||
|
||||
// scrape a stream
|
||||
const stream = await providers.runAll({
|
||||
media: media,
|
||||
})
|
||||
|
||||
// scrape a stream, but prioritize flixhq above all
|
||||
// (other scrapers are still run if flixhq fails, it just has priority)
|
||||
const flixhqStream = await providers.runAll({
|
||||
media: media,
|
||||
sourceOrder: ['flixhq']
|
||||
})
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function runAll(runnerOps: RunnerOptions): Promise<RunOutput | null>;
|
||||
|
||||
interface RunnerOptions {
|
||||
// overwrite the order of sources to run. List of IDs
|
||||
// any omitted IDs are added to the end in order of rank (highest first)
|
||||
sourceOrder?: string[];
|
||||
|
||||
// overwrite the order of embeds to run. List of IDs
|
||||
// any omitted IDs are added to the end in order of rank (highest first)
|
||||
embedOrder?: string[];
|
||||
|
||||
// object of event functions
|
||||
events?: FullScraperEvents;
|
||||
|
||||
// the media you want to see sources from
|
||||
media: ScrapeMedia;
|
||||
}
|
||||
|
||||
type RunOutput = {
|
||||
// source scraper ID
|
||||
sourceId: string;
|
||||
|
||||
// if from an embed, this is the embed scraper ID
|
||||
embedId?: string;
|
||||
|
||||
// the emitted stream
|
||||
stream: Stream;
|
||||
};
|
||||
```
|
24
.docs/pages/api-reference/ProviderControlsgetMetadata.md
Normal file
24
.docs/pages/api-reference/ProviderControlsgetMetadata.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# `ProviderControls.getMetadata`
|
||||
|
||||
Get meta data for a scraper, can be either source or embed scraper.
|
||||
Returns `null` if the `id` is not recognized.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const flixhqSource = providers.getMetadata('flixhq');
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function getMetadata(id: string): MetaOutput | null;
|
||||
|
||||
type MetaOutput = {
|
||||
type: 'embed' | 'source';
|
||||
id: string;
|
||||
rank: number;
|
||||
name: string;
|
||||
mediaTypes?: Array<MediaTypes>;
|
||||
};
|
||||
```
|
25
.docs/pages/api-reference/ProviderControlslistEmbeds.md
Normal file
25
.docs/pages/api-reference/ProviderControlslistEmbeds.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# `ProviderControls.listEmbeds`
|
||||
|
||||
List all embed scrapers that are applicable for the target.
|
||||
They are sorted by rank; highest first
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const embedScrapers = providers.listEmbeds();
|
||||
// Guaranteed to only return the type: 'embed'
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function listEmbeds(): MetaOutput[];
|
||||
|
||||
type MetaOutput = {
|
||||
type: 'embed' | 'source';
|
||||
id: string;
|
||||
rank: number;
|
||||
name: string;
|
||||
mediaTypes?: Array<MediaTypes>;
|
||||
};
|
||||
```
|
25
.docs/pages/api-reference/ProviderControlslistSources.md
Normal file
25
.docs/pages/api-reference/ProviderControlslistSources.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# `ProviderControls.listSources`
|
||||
|
||||
List all source scrapers that are applicable for the target.
|
||||
They are sorted by rank; highest first
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const sourceScrapers = providers.listSources();
|
||||
// Guaranteed to only return the type: 'source'
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function listSources(): MetaOutput[];
|
||||
|
||||
type MetaOutput = {
|
||||
type: 'embed' | 'source';
|
||||
id: string;
|
||||
rank: number;
|
||||
name: string;
|
||||
mediaTypes?: Array<MediaTypes>;
|
||||
};
|
||||
```
|
44
.docs/pages/api-reference/ProviderControlsrunEmbedScraper.md
Normal file
44
.docs/pages/api-reference/ProviderControlsrunEmbedScraper.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# `ProviderControls.runEmbedScraper`
|
||||
|
||||
Run a specific embed scraper and get its emitted streams.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { SourcererOutput } from '@movie-web/providers';
|
||||
|
||||
// scrape a stream from upcloud
|
||||
let output: EmbedOutput;
|
||||
try {
|
||||
output = await providers.runEmbedScraper({
|
||||
id: 'upcloud',
|
||||
url: 'https://example.com/123',
|
||||
})
|
||||
} catch (err) {
|
||||
console.log('failed to scrape')
|
||||
return;
|
||||
}
|
||||
|
||||
// output.stream now has your stream
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function runEmbedScraper(runnerOps: SourceRunnerOptions): Promise<EmbedOutput>;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
type EmbedOutput = {
|
||||
stream: Stream;
|
||||
};
|
||||
```
|
@@ -0,0 +1,66 @@
|
||||
# `ProviderControls.runSourceScraper`
|
||||
|
||||
Run a specific source scraper and get its emitted streams.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { ScrapeMedia , SourcererOutput, NotFoundError } from '@movie-web/providers';
|
||||
|
||||
// media from TMDB
|
||||
const media : ScrapeMedia = {
|
||||
type: 'movie',
|
||||
title: 'Hamilton',
|
||||
releaseYear: 2020,
|
||||
tmdbId: '556574'
|
||||
}
|
||||
|
||||
// scrape a stream from flixhq
|
||||
let output: SourcererOutput;
|
||||
try {
|
||||
output = await providers.runSourceScraper({
|
||||
id: 'flixhq',
|
||||
media: media,
|
||||
})
|
||||
} catch (err) {
|
||||
if (err instanceof NotFoundError) {
|
||||
console.log('source does not have this media');
|
||||
} else {
|
||||
console.log('failed to scrape')
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!output.stream && output.embeds.length === 0) {
|
||||
console.log('no streams found');
|
||||
}
|
||||
```
|
||||
|
||||
## 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;
|
||||
};
|
||||
```
|
3
.docs/pages/api-reference/_dir.yml
Normal file
3
.docs/pages/api-reference/_dir.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
icon: ph:code-simple-fill
|
||||
navigation.redirect: /api/makeproviders
|
||||
navigation.title: "Api reference"
|
3
.docs/pages/api-reference/index.tsx
Normal file
3
.docs/pages/api-reference/index.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
import { createRedirect } from '@neato/guider/client';
|
||||
|
||||
export default createRedirect({ to: '/api-reference/makeProviders' });
|
34
.docs/pages/api-reference/makeProviders.md
Normal file
34
.docs/pages/api-reference/makeProviders.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# `makeProviders`
|
||||
|
||||
Make an instance of provider controls with configuration.
|
||||
This is the main entry-point of the library. It is recommended to make one instance globally and reuse it throughout your application.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { targets, makeProviders, makeDefaultFetcher } from '@movie-web/providers';
|
||||
|
||||
const providers = makeProviders({
|
||||
fetcher: makeDefaultFetcher(fetch),
|
||||
target: targets.NATIVE, // target native app streams
|
||||
});
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function makeProviders(ops: ProviderBuilderOptions): ProviderControls;
|
||||
|
||||
interface ProviderBuilderOptions {
|
||||
// instance of a fetcher, all webrequests are made with the fetcher.
|
||||
fetcher: Fetcher;
|
||||
|
||||
// instance of a fetcher, in case the request has CORS restrictions.
|
||||
// this fetcher will be called instead of normal fetcher.
|
||||
// if your environment doesn't have CORS restrictions (like Node.JS), there is no need to set this.
|
||||
proxiedFetcher?: Fetcher;
|
||||
|
||||
// target to get streams for
|
||||
target: Targets;
|
||||
}
|
||||
```
|
23
.docs/pages/api-reference/makeSimpleProxyFetcher.md
Normal file
23
.docs/pages/api-reference/makeSimpleProxyFetcher.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# `makeSimpleProxyFetcher`
|
||||
|
||||
Make a fetcher to use with [movie-web/simple-proxy](https://github.com/movie-web/simple-proxy). This is for making a proxiedFetcher, so you can run this library in the browser.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { targets, makeProviders, makeDefaultFetcher, makeSimpleProxyFetcher } from '@movie-web/providers';
|
||||
|
||||
const proxyUrl = 'https://your.proxy.workers.dev/'
|
||||
|
||||
const providers = makeProviders({
|
||||
fetcher: makeDefaultFetcher(fetch),
|
||||
proxiedFetcher: makeSimpleProxyFetcher(proxyUrl, fetch),
|
||||
target: targets.BROWSER,
|
||||
});
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function makeSimpleProxyFetcher(proxyUrl: string, fetchApi: typeof fetch): Fetcher;
|
||||
```
|
20
.docs/pages/api-reference/makeStandardFetcher.md
Normal file
20
.docs/pages/api-reference/makeStandardFetcher.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# `makeStandardFetcher`
|
||||
|
||||
Make a fetcher from a `fetch()` API. It is used for making an instance of provider controls.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { targets, makeProviders, makeDefaultFetcher } from '@movie-web/providers';
|
||||
|
||||
const providers = makeProviders({
|
||||
fetcher: makeStandardFetcher(fetch),
|
||||
target: targets.ANY,
|
||||
});
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function makeStandardFetcher(fetchApi: typeof fetch): Fetcher;
|
||||
```
|
Reference in New Issue
Block a user