mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 17:53:24 +00:00
Doc directory structure
This commit is contained in:
34
.docs/content/5.Api reference/0.makeProviders.md
Normal file
34
.docs/content/5.Api reference/0.makeProviders.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# `makeProviders`
|
||||
|
||||
Make an instance of providers with configuration.
|
||||
This is the main entrypoint 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 doesnt have cors restrictions (like nodejs), there is no need to set this.
|
||||
proxiedFetcher?: Fetcher;
|
||||
|
||||
// target to get streams for
|
||||
target: Targets;
|
||||
}
|
||||
```
|
61
.docs/content/5.Api reference/1.ProviderControlsRunAll.md
Normal file
61
.docs/content/5.Api reference/1.ProviderControlsRunAll.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# `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 its processing.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
// media from TMDB
|
||||
const media = {
|
||||
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 stil ran 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 in 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 in 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 outputed stream
|
||||
stream: Stream;
|
||||
};
|
||||
```
|
@@ -0,0 +1,66 @@
|
||||
# `ProviderControls.runSourceScraper`
|
||||
|
||||
Run a specific source scraper and get its outputted streams.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { SourcererOutput, NotFoundError } from "@movie-web/providers";
|
||||
|
||||
// media from TMDB
|
||||
const media = {
|
||||
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 doesnt 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;
|
||||
};
|
||||
```
|
@@ -0,0 +1,44 @@
|
||||
# `ProviderControls.runEmbedScraper`
|
||||
|
||||
Run a specific embed scraper and get its outputted 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,25 @@
|
||||
# `ProviderControls.listSources`
|
||||
|
||||
List all source scrapers that applicable for the target.
|
||||
They are sorted by rank, highest first
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const sourceScrapers = providers.listSources();
|
||||
// Guaranteed to only return type: 'source'
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function listSources(): MetaOutput[];
|
||||
|
||||
type MetaOutput = {
|
||||
type: 'embed' | 'source';
|
||||
id: string;
|
||||
rank: number;
|
||||
name: string;
|
||||
mediaTypes?: Array<MediaTypes>;
|
||||
};
|
||||
```
|
@@ -0,0 +1,25 @@
|
||||
# `ProviderControls.listEmbeds`
|
||||
|
||||
List all embed scrapers that applicable for the target.
|
||||
They are sorted by rank, highest first
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const embedScrapers = providers.listEmbeds();
|
||||
// Guaranteed to only return type: 'embed'
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function listEmbeds(): MetaOutput[];
|
||||
|
||||
type MetaOutput = {
|
||||
type: 'embed' | 'source';
|
||||
id: string;
|
||||
rank: number;
|
||||
name: string;
|
||||
mediaTypes?: Array<MediaTypes>;
|
||||
};
|
||||
```
|
@@ -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>;
|
||||
};
|
||||
```
|
20
.docs/content/5.Api reference/7.makeStandardFetcher.md
Normal file
20
.docs/content/5.Api reference/7.makeStandardFetcher.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# `makeStandardFetcher`
|
||||
|
||||
Make a fetcher from a `fetch()` API. It is used for making a instance of providers with `makeProviders()`.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { targets, makeProviders, makeDefaultFetcher } from "@movie-web/providers";
|
||||
|
||||
const providers = makeProviders({
|
||||
fetcher: makeDefaultFetcher(fetch),
|
||||
target: targets.NATIVE,
|
||||
});
|
||||
```
|
||||
|
||||
## Type
|
||||
|
||||
```ts
|
||||
function makeDefaultFetcher(fetchApi: typeof fetch): Fetcher;
|
||||
```
|
23
.docs/content/5.Api reference/8.makeSimpleProxyFetcher.md
Normal file
23
.docs/content/5.Api reference/8.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;
|
||||
```
|
2
.docs/content/5.Api reference/_dir.yml
Normal file
2
.docs/content/5.Api reference/_dir.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
icon: ph:file-code-fill
|
||||
navigation.redirect: /api/makeproviders
|
Reference in New Issue
Block a user