providers/.docs/content/1.get-started/1.quick-start.md

61 lines
1.5 KiB
Markdown
Raw Normal View History

2023-12-26 22:35:58 +00:00
# Quick start
2023-12-26 23:15:23 +00:00
## Installation
2023-09-14 19:07:35 +00:00
Let's get started with `@movie-web/providers`. First lets install the package.
::code-group
```bash [NPM]
npm install @movie-web/providers
```
```bash [Yarn]
yarn add @movie-web/providers
```
```bash [PNPM]
pnpm install @movie-web/providers
```
::
## Scrape your first item
To get started with scraping on the **server**, first you have to make an instance of the providers.
2023-12-26 23:15:23 +00:00
::alert{type="warning"}
2023-12-29 16:05:01 +00:00
This snippet will only work on a **server**, for other environments, check out [Usage on X](../2.essentials/0.usage-on-x.md).
2023-12-26 23:15:23 +00:00
::
```ts [index.ts (server)]
import { makeProviders, makeStandardFetcher, targets } from '@movie-web/providers';
2023-09-14 19:07:35 +00:00
2023-09-27 17:00:40 +00:00
// this is how the library will make http requests
2023-12-26 23:15:23 +00:00
const myFetcher = makeStandardFetcher(fetch);
2023-09-14 19:07:35 +00:00
2023-09-27 17:00:40 +00:00
// make an instance of the providers library
const providers = makeProviders({
fetcher: myFetcher,
2023-09-14 19:07:35 +00:00
2023-09-27 17:00:40 +00:00
// will be played on a native video player
target: targets.NATIVE
})
```
2023-09-14 19:07:35 +00:00
2023-12-26 23:15:23 +00:00
Perfect, this instance of the providers you can reuse everywhere where you need to.
Now lets actually scrape an item:
2023-09-14 19:07:35 +00:00
2023-09-27 17:00:40 +00:00
```ts [index.ts (server)]
// fetch some data from TMDB
const media = {
type: 'movie',
title: "Hamilton",
releaseYear: 2020,
tmdbId: "556574"
}
const output = await providers.runAll({
media: media
})
```
2023-12-26 23:15:23 +00:00
Now we have our stream in the output variable. (If the output is `null` then nothing could be found.)
2023-12-29 16:05:01 +00:00
To find out how to use the streams, check out [Using streams](../2.essentials/4.using-streams.md).