mirror of
https://github.com/p-stream/providers.git
synced 2026-01-11 20:10:33 +00:00
1.7 KiB
1.7 KiB
Quick start
Installation
Let's get started with @p-stream/providers. First lets install the package.
::alert{type="warning"}
Note: The @p-stream/providers package is not published on npm. Install it directly from GitHub using the following commands:
::
::code-group
npm install @p-stream/providers@github:p-stream/providers#production
yarn add @p-stream/providers@github:p-stream/providers#production
pnpm add @p-stream/providers@github:p-stream/providers#production
::
Scrape your first item
To get started with scraping on the server, first you have to make an instance of the providers.
::alert{type="warning"} This snippet will only work on a server. For other environments, check out Usage on X. ::
import { makeProviders, makeStandardFetcher, targets } from '@p-stream/providers';
// this is how the library will make http requests
const myFetcher = makeStandardFetcher(fetch);
// make an instance of the providers library
const providers = makeProviders({
fetcher: myFetcher,
// will be played on a native video player
target: targets.NATIVE
})
Perfect. You now have an instance of the providers you can reuse everywhere. Now let's scrape an item:
// fetch some data from TMDB
const media = {
type: 'movie',
title: "Hamilton",
releaseYear: 2020,
tmdbId: "556574"
}
const output = await providers.runAll({
media: media
})
Now we have our stream in the output variable. (If the output is null then nothing could be found.)
To find out how to use the streams, check out Using streams.