providers/.docs/content/2.essentials/3.customize-providers.md

75 lines
2.6 KiB
Markdown
Raw Normal View History

2023-12-26 22:35:58 +00:00
# Customize providers
2023-12-31 03:35:48 +00:00
You make the provider controls in two ways. Either with `makeProviders()` (the simpler option) or with `buildProviders()` (more elaborate and extensive option).
2023-12-26 23:15:23 +00:00
2023-12-29 15:59:30 +00:00
## `makeProviders()` (simple)
To know what to set the configuration to, you can read [How to use on X](./0.usage-on-x.md) for a detailed guide on how to configure your controls.
```ts
const providers = makeProviders({
// fetcher, every web request gets called through here
fetcher: makeStandardFetcher(fetch),
// proxied fetcher, if the scraper needs to access a CORS proxy. this fetcher will be called instead
// of the normal fetcher. Defaults to the normal fetcher.
proxiedFetcher: undefined;
// target of where the streams will be used
target: targets.NATIVE;
// Set this to true, if the requests will have the same IP as
// the device that the stream will be played on.
consistentIpForRequests: false;
})
```
## `buildProviders()` (advanced)
To know what to set the configuration to, you can read [How to use on X](./0.usage-on-x.md) for a detailed guide on how to configure your controls.
### Standard setup
```ts
const providers = buildProviders()
.setTarget(targets.NATIVE) // target of where the streams will be used
.setFetcher(makeStandardFetcher(fetch)) // fetcher, every web request gets called through here
.addBuiltinProviders() // add all builtin providers, if this is not called, no providers will be added to the controls
.build();
```
### Adding only select few providers
2023-12-31 03:35:48 +00:00
Not all providers are great quality, so you can make an instance of the controls with only the providers you want.
2023-12-29 15:59:30 +00:00
```ts
const providers = buildProviders()
.setTarget(targets.NATIVE) // target of where the streams will be used
.setFetcher(makeStandardFetcher(fetch)) // fetcher, every web request gets called through here
.addSource('showbox') // only add showbox source
.addEmbed('febbox-hls') // add febbox-hls embed, which is returned by showbox
.build();
```
### Adding your own scrapers to the providers
2023-12-31 03:35:48 +00:00
If you have your own scraper and still want to use the nice utilities of the provider library or just want to add on to the built-in providers, you can add your own custom source.
2023-12-29 15:59:30 +00:00
```ts
const providers = buildProviders()
.setTarget(targets.NATIVE) // target of where the streams will be used
.setFetcher(makeStandardFetcher(fetch)) // fetcher, every web request gets called through here
.addSource({ // add your own source
id: 'my-scraper',
name: 'My scraper',
rank: 800,
flags: [],
scrapeMovie(ctx) {
2023-12-29 16:47:49 +00:00
throw new Error('Not implemented');
2023-12-29 15:59:30 +00:00
}
})
.build();
```