mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 10:33:25 +00:00
Merge pull request #67 from movie-web/dev
Version 2.0.4: Providers and Fixes™️
This commit is contained in:
@@ -21,7 +21,7 @@ Let's get started with `@movie-web/providers`. First lets install the package.
|
||||
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](../2.essentials/0.usage-on-x.md).
|
||||
This snippet will only work on a **server**. For other environments, check out [Usage on X](../2.essentials/0.usage-on-x.md).
|
||||
::
|
||||
|
||||
```ts [index.ts (server)]
|
||||
@@ -39,8 +39,8 @@ const providers = makeProviders({
|
||||
})
|
||||
```
|
||||
|
||||
Perfect, this instance of the providers you can reuse everywhere where you need to.
|
||||
Now lets actually scrape an item:
|
||||
Perfect. You now have an instance of the providers you can reuse everywhere.
|
||||
Now let's scrape an item:
|
||||
|
||||
```ts [index.ts (server)]
|
||||
// fetch some data from TMDB
|
||||
|
@@ -2,6 +2,27 @@
|
||||
title: 'Changelog'
|
||||
---
|
||||
|
||||
# Version 2.0.4
|
||||
- Added providers:
|
||||
- Add VidSrcTo provider with Vidplay and Filemoon embeds
|
||||
- Add VidSrc provider with StreamBucket embeds
|
||||
- Fixed providers:
|
||||
- RemoteStream
|
||||
- LookMovie - Fixed captions
|
||||
- ShowBox
|
||||
- Updated documentation to fix spelling + grammar
|
||||
- User-agent header fix
|
||||
- Needs the latest simple-proxy update
|
||||
- Added utility to not return multiple subs for the same language - Applies to Lookmovie and Showbox
|
||||
|
||||
# Version 2.0.3
|
||||
- Actually remove Febbox HLS
|
||||
|
||||
# Version 2.0.2
|
||||
- Added Lookmovie caption support
|
||||
- Fix Febbox duplicate subtitle languages
|
||||
- Remove Febbox HLS
|
||||
|
||||
# Version 2.0.1
|
||||
- Fixed issue where febbox-mp4 would not show all qualities
|
||||
- Fixed issue where discoverEmbeds event would not show the embeds in the right order
|
||||
@@ -22,7 +43,7 @@ There are breaking changes in this list, make sure to read them thoroughly if yo
|
||||
- Fetchers can now return a full response with headers and everything
|
||||
|
||||
**New features:**
|
||||
- Added system to allow scraping ip locked sources through the consistentIpforRequests option.
|
||||
- Added system to allow scraping IP locked sources through the consistentIpforRequests option.
|
||||
- There is now a `buildProviders()` function that gives a builder for the `ProviderControls`. It's an alternative to `makeProviders()`.
|
||||
- Streams can now return a headers object and a `preferredHeaders` object. which is required and optional headers for when using the stream.
|
||||
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|
||||
The library can run in many environments, so it can be tricky to figure out how to set it up.
|
||||
|
||||
So here is a checklist, for more specific environments, keep reading below:
|
||||
Here is a checklist. For more specific environments, keep reading below:
|
||||
- When requests are very restricted (like browser client-side). Configure a proxied fetcher.
|
||||
- When your requests come from the same device it will be streamed on (Not compatible with proxied fetcher). Set `consistentIpForRequests: true`.
|
||||
- When your requests come from the same device on which it will be streamed (not compatible with proxied fetcher). Set `consistentIpForRequests: true`.
|
||||
- To set a target. Consult [Targets](./1.targets.md).
|
||||
|
||||
To make use of the examples below, You check check out the following pages:
|
||||
To make use of the examples below, check out the following pages:
|
||||
- [Quick start](../1.get-started/1.quick-start.md)
|
||||
- [Using streams](../2.essentials/4.using-streams.md)
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
When creating provider controls, you will immediately be required to choose a target.
|
||||
|
||||
::alert{type="warning"}
|
||||
A target is the device where the stream will be played on.
|
||||
A target is the device on which the stream will be played.
|
||||
**Where the scraping is run has nothing to do with the target**, only where the stream is finally played in the end is significant in choosing a target.
|
||||
::
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# Fetchers
|
||||
|
||||
When creating provider controls, it will need you to configure a fetcher.
|
||||
This comes with some considerations depending on the environment youre running.
|
||||
When creating provider controls, a fetcher will need to be configured.
|
||||
Depending on your environment, this can come with some considerations:
|
||||
|
||||
## Using `fetch()`
|
||||
In most cases, you can use the `fetch()` API. This will work in newer versions of Node.js (18 and above) and on the browser.
|
||||
@@ -19,7 +19,7 @@ const fetcher = makeStandardFetcher(fetch);
|
||||
```
|
||||
|
||||
## Using fetchers on the browser
|
||||
When using this library on a browser, you will need a proxy. Browsers come with many restrictions on when a web request can be made, and to bypass those restrictions, you will need a cors proxy.
|
||||
When using this library on a browser, you will need a proxy. Browsers restrict when a web request can be made. To bypass those restrictions, you will need a CORS proxy.
|
||||
|
||||
The movie-web team has a proxy pre-made and pre-configured for you to use. For more information, check out [movie-web/simple-proxy](https://github.com/movie-web/simple-proxy). After installing, you can use this proxy like so:
|
||||
|
||||
@@ -31,13 +31,13 @@ If you aren't able to use this specific proxy and need to use a different one, y
|
||||
|
||||
## Making a derived fetcher
|
||||
|
||||
In some rare cases, a custom fetcher will need to be made. This can be quite difficult to do from scratch so it's recommended to base it off an existing fetcher and building your own functionality around it.
|
||||
In some rare cases, a custom fetcher is necessary. This can be quite difficult to make from scratch so it's recommended to base it off of an existing fetcher and building your own functionality around it.
|
||||
|
||||
```ts
|
||||
export function makeCustomFetcher(): Fetcher {
|
||||
const fetcher = makeStandardFetcher(f);
|
||||
const customFetcher: Fetcher = (url, ops) => {
|
||||
// Do something with the options and url here
|
||||
// Do something with the options and URL here
|
||||
return fetcher(url, ops);
|
||||
};
|
||||
|
||||
@@ -45,19 +45,19 @@ export function makeCustomFetcher(): Fetcher {
|
||||
}
|
||||
```
|
||||
|
||||
If you need to make your own fetcher for a proxy. Make sure you make it compatible with the following headers: `Set-Cookie`, `Cookie`, `Referer`, `Origin`. Proxied fetchers need to be able to write/read those headers when making a request.
|
||||
If you need to make your own fetcher for a proxy, ensure you make it compatible with the following headers: `Set-Cookie`, `Cookie`, `Referer`, `Origin`. Proxied fetchers need to be able to write/read those headers when making a request.
|
||||
|
||||
|
||||
## Making a fetcher from scratch
|
||||
|
||||
In some even rare cases, you need to make one completely from scratch.
|
||||
In some rare cases, you need to make a fetcher from scratch.
|
||||
This is the list of features it needs:
|
||||
- Send/read every header
|
||||
- Parse JSON, otherwise parse as text
|
||||
- Send JSON, Formdata or normal strings
|
||||
- get final destination url
|
||||
- get final destination URL
|
||||
|
||||
It's not recommended to do this at all, but if you have to. You can base your code on the original implementation of `makeStandardFetcher`. Check the out [source code for it here](https://github.com/movie-web/providers/blob/dev/src/fetchers/standardFetch.ts).
|
||||
It's not recommended to do this at all. If you have to, you can base your code on the original implementation of `makeStandardFetcher`. Check out the [source code for it here](https://github.com/movie-web/providers/blob/dev/src/fetchers/standardFetch.ts).
|
||||
|
||||
Here is a basic template on how to make your own custom fetcher:
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
# Customize providers
|
||||
|
||||
You make a provider controls in two ways. Either with `makeProviders()` (the simpler option) or with `buildProviders()` (more elaborate and extensive option).
|
||||
You make the provider controls in two ways. Either with `makeProviders()` (the simpler option) or with `buildProviders()` (more elaborate and extensive option).
|
||||
|
||||
## `makeProviders()` (simple)
|
||||
|
||||
@@ -41,7 +41,7 @@ const providers = buildProviders()
|
||||
|
||||
### Adding only select few providers
|
||||
|
||||
Not all providers are great quality, so you can make a instance of the controls with only the providers you want.
|
||||
Not all providers are great quality, so you can make an instance of the controls with only the providers you want.
|
||||
|
||||
```ts
|
||||
const providers = buildProviders()
|
||||
@@ -55,7 +55,7 @@ const providers = buildProviders()
|
||||
|
||||
### Adding your own scrapers to the providers
|
||||
|
||||
If you have your own scraper and still want to use the nice utils of the provider library or just want to add on to the builtin providers. You can add your own custom source.
|
||||
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.
|
||||
|
||||
```ts
|
||||
const providers = buildProviders()
|
||||
|
@@ -12,11 +12,11 @@ All streams have the same common parameters:
|
||||
- `Stream.headers`: Either undefined or a key value object of headers you must set to use the stream.
|
||||
- `Stream.preferredHeaders`: Either undefined or a key value object of headers you may want to set if you want optimal playback - but not required.
|
||||
|
||||
Now let's delve deeper into how to actually watch these streams!
|
||||
Now let's delve deeper into how to watch these streams!
|
||||
|
||||
## Streams with type `hls`
|
||||
|
||||
HLS streams can be tough to watch, it's not a normal file you can just use.
|
||||
HLS streams can be tough to watch. They're not normal files you can just use.
|
||||
These streams have an extra property `Stream.playlist` which contains the m3u8 playlist.
|
||||
|
||||
Here is a code sample of how to use HLS streams in web context using hls.js
|
||||
@@ -39,17 +39,17 @@ Here is a code sample of how to use HLS streams in web context using hls.js
|
||||
|
||||
## Streams with type `file`
|
||||
|
||||
File streams are quite easy to use, it just returns a new property: `Stream.qualities`.
|
||||
This property is a map of quality and a stream file. So if you want to get 1080p quality you do `stream["1080"]` to get your stream file. It will return undefined if there is no quality like that.
|
||||
File streams are quite easy to use, they just return a new property: `Stream.qualities`.
|
||||
This property is a map of quality and a stream file. So if you want to get 1080p quality you do `stream["1080"]` to get your stream file. It will return undefined if that quality is absent.
|
||||
|
||||
The possibly qualities are: `unknown`, `360`, `480`, `720`, `1080`, `4k`.
|
||||
File based streams are garuanteed to always have one quality.
|
||||
File based streams are always guaranteed to have one quality.
|
||||
|
||||
Once you get a streamfile, you have the following parameters:
|
||||
- `StreamFile.type`: Right now it can only be `mp4`.
|
||||
- `StreamFile.url`: The URL linking to the video file.
|
||||
|
||||
Here is a code sample of how to watch a file based stream the video in a browser:
|
||||
Here is a code sample of how to watch a file based stream in a browser:
|
||||
|
||||
```html
|
||||
<video id="video"></video>
|
||||
@@ -66,9 +66,9 @@ Here is a code sample of how to watch a file based stream the video in a browser
|
||||
## Streams with headers
|
||||
|
||||
Streams have both a `Stream.headers` and a `Stream.preferredHeaders`.
|
||||
The difference between the two is that `Stream.headers` **must** be set in other for the stream to work. While the other one is optional, and can only enhance the quality or performance.
|
||||
The difference between the two is that `Stream.headers` **must** be set in order for the stream to work. While the other is optional, and enhances the quality or performance.
|
||||
|
||||
If your target is set to `BROWSER`. There will never be required headers, as it's not possible to do.
|
||||
If your target is set to `BROWSER`, headers will never be required, as it's not possible to do.
|
||||
|
||||
## Using captions/subtitles
|
||||
|
||||
@@ -77,7 +77,7 @@ All streams have a list of captions at `Stream.captions`. The structure looks li
|
||||
type Caption = {
|
||||
type: CaptionType; // Language type, either "srt" or "vtt"
|
||||
id: string; // Unique per stream
|
||||
url: string; // The url pointing to the subtitle file
|
||||
url: string; // The URL pointing to the subtitle file
|
||||
hasCorsRestrictions: boolean; // If true, you will need to proxy it if you're running in a browser
|
||||
language: string; // Language code of the caption
|
||||
};
|
||||
|
@@ -1,10 +1,10 @@
|
||||
# Flags
|
||||
|
||||
Flags is the primary way the library seperates entities between different environments.
|
||||
For example some sources only give back content that has the CORS headers set to allow anyone, so that source gets the flag `CORS_ALLOWED`. Now if you set your target to `BROWSER`, sources without that flag won't even get listed.
|
||||
Flags is the primary way the library separates entities between different environments.
|
||||
For example, some sources only give back content that has the CORS headers set to allow anyone, so that source gets the flag `CORS_ALLOWED`. Now if you set your target to `BROWSER`, sources without that flag won't even get listed.
|
||||
|
||||
This concept is applied in multiple away across the library.
|
||||
|
||||
## Flag options
|
||||
- `CORS_ALLOWED`: Headers from the output streams are set to allow any origin.
|
||||
- `IP_LOCKED`: The streams are locked by ip, requester and watcher must be the same.
|
||||
- `IP_LOCKED`: The streams are locked by IP: requester and watcher must be the same.
|
||||
|
@@ -15,13 +15,13 @@ TODO
|
||||
## Testing using the CLI
|
||||
|
||||
Testing can be quite difficult for this library, unit tests can't really be made because of the unreliable nature of scrapers.
|
||||
But manually testing by writing an entrypoint is also really annoying.
|
||||
But manually testing by writing an entry-point is also really annoying.
|
||||
|
||||
Our solution is to make a CLI that you can use to run the scrapers, for everything else there are unit tests.
|
||||
Our solution is to make a CLI that you can use to run the scrapers. For everything else there are unit tests.
|
||||
|
||||
### Setup
|
||||
Make a `.env` file in the root of the repository and add a TMDB api key: `MOVIE_WEB_TMDB_API_KEY=KEY_HERE`.
|
||||
Then make sure you've ran `npm i` to get all the dependencies.
|
||||
Make a `.env` file in the root of the repository and add a TMDB API key: `MOVIE_WEB_TMDB_API_KEY=KEY_HERE`.
|
||||
Then make sure you've run `npm i` to get all the dependencies.
|
||||
|
||||
### Mode 1 - interactive
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# `makeProviders`
|
||||
|
||||
Make an instance of provider controls with configuration.
|
||||
This is the main entrypoint of the library. It is recommended to make one instance globally and reuse it throughout your application.
|
||||
This is the main entry-point of the library. It is recommended to make one instance globally and reuse it throughout your application.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -23,9 +23,9 @@ 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.
|
||||
// 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 Node.JS), there is no need to set this.
|
||||
// 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
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# `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.
|
||||
You can attach events if you need to know what is going on while it is processing.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -20,7 +20,7 @@ const stream = await providers.runAll({
|
||||
})
|
||||
|
||||
// scrape a stream, but prioritize flixhq above all
|
||||
// (other scrapers are stil ran if flixhq fails, it just has priority)
|
||||
// (other scrapers are still run if flixhq fails, it just has priority)
|
||||
const flixhqStream = await providers.runAll({
|
||||
media: media,
|
||||
sourceOrder: ['flixhq']
|
||||
@@ -33,12 +33,12 @@ const flixhqStream = await providers.runAll({
|
||||
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)
|
||||
// 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 in added to the end in order of rank (highest first)
|
||||
// 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
|
||||
@@ -49,13 +49,13 @@ interface RunnerOptions {
|
||||
}
|
||||
|
||||
type RunOutput = {
|
||||
// source scraper id
|
||||
// source scraper ID
|
||||
sourceId: string;
|
||||
|
||||
// if from an embed, this is the embed scraper id
|
||||
// if from an embed, this is the embed scraper ID
|
||||
embedId?: string;
|
||||
|
||||
// the outputed stream
|
||||
// the emitted stream
|
||||
stream: Stream;
|
||||
};
|
||||
```
|
||||
|
@@ -1,6 +1,6 @@
|
||||
# `ProviderControls.runSourceScraper`
|
||||
|
||||
Run a specific source scraper and get its outputted streams.
|
||||
Run a specific source scraper and get its emitted streams.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -24,7 +24,7 @@ try {
|
||||
})
|
||||
} catch (err) {
|
||||
if (err instanceof NotFoundError) {
|
||||
console.log('source doesnt have this media');
|
||||
console.log('source does not have this media');
|
||||
} else {
|
||||
console.log('failed to scrape')
|
||||
}
|
||||
@@ -48,13 +48,13 @@ interface SourceRunnerOptions {
|
||||
// the media you want to see sources from
|
||||
media: ScrapeMedia;
|
||||
|
||||
// id of the source scraper you want to scrape from
|
||||
// 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
|
||||
// embed ID is a reference to an embed scraper
|
||||
embeds: {
|
||||
embedId: string;
|
||||
url: string;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
# `ProviderControls.runEmbedScraper`
|
||||
|
||||
Run a specific embed scraper and get its outputted streams.
|
||||
Run a specific embed scraper and get its emitted streams.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -31,10 +31,10 @@ interface EmbedRunnerOptions {
|
||||
// object of event functions
|
||||
events?: IndividualScraperEvents;
|
||||
|
||||
// the embed url
|
||||
// the embed URL
|
||||
url: string;
|
||||
|
||||
// id of the embed scraper you want to scrape from
|
||||
// ID of the embed scraper you want to scrape from
|
||||
id: string;
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
# `ProviderControls.listSources`
|
||||
|
||||
List all source scrapers that applicable for the target.
|
||||
They are sorted by rank, highest first
|
||||
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 type: 'source'
|
||||
// Guaranteed to only return the type: 'source'
|
||||
```
|
||||
|
||||
## Type
|
||||
|
@@ -1,13 +1,13 @@
|
||||
# `ProviderControls.listEmbeds`
|
||||
|
||||
List all embed scrapers that applicable for the target.
|
||||
They are sorted by rank, highest first
|
||||
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 type: 'embed'
|
||||
// Guaranteed to only return the type: 'embed'
|
||||
```
|
||||
|
||||
## Type
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# `ProviderControls.getMetadata`
|
||||
|
||||
Get meta data for a scraper, can be either source or embed scraper.
|
||||
Returns null if the `id` is not recognized.
|
||||
Returns `null` if the `id` is not recognized.
|
||||
|
||||
## Example
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
# `makeStandardFetcher`
|
||||
|
||||
Make a fetcher from a `fetch()` API. It is used for making a instance of provider controls.
|
||||
Make a fetcher from a `fetch()` API. It is used for making an instance of provider controls.
|
||||
|
||||
## Example
|
||||
|
||||
|
@@ -18,6 +18,8 @@ module.exports = {
|
||||
},
|
||||
plugins: ['@typescript-eslint', 'import', 'prettier'],
|
||||
rules: {
|
||||
'no-plusplus': 'off',
|
||||
'no-bitwise': 'off',
|
||||
'no-underscore-dangle': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'no-console': 'off',
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@movie-web/providers",
|
||||
"version": "2.0.3",
|
||||
"version": "2.0.4",
|
||||
"description": "Package that contains all the providers of movie-web",
|
||||
"main": "./lib/index.umd.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
|
@@ -41,6 +41,7 @@ async function runBrowserScraping(
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
page.on('console', (message) => console.log(`${message.type().slice(0, 3).toUpperCase()} ${message.text()}`));
|
||||
await page.goto(server.resolvedUrls.local[0]);
|
||||
await page.waitForFunction('!!window.scrape', { timeout: 5000 });
|
||||
|
||||
|
@@ -2,7 +2,7 @@ import { getConfig } from '@/dev-cli/config';
|
||||
|
||||
import { MovieMedia, ShowMedia } from '..';
|
||||
|
||||
export async function makeTMDBRequest(url: string): Promise<Response> {
|
||||
export async function makeTMDBRequest(url: string, appendToResponse?: string): Promise<Response> {
|
||||
const headers: {
|
||||
accept: 'application/json';
|
||||
authorization?: string;
|
||||
@@ -10,7 +10,7 @@ export async function makeTMDBRequest(url: string): Promise<Response> {
|
||||
accept: 'application/json',
|
||||
};
|
||||
|
||||
let requestURL = url;
|
||||
const requestURL = new URL(url);
|
||||
const key = getConfig().tmdbApiKey;
|
||||
|
||||
// * JWT keys always start with ey and are ONLY valid as a header.
|
||||
@@ -19,7 +19,11 @@ export async function makeTMDBRequest(url: string): Promise<Response> {
|
||||
if (key.startsWith('ey')) {
|
||||
headers.authorization = `Bearer ${key}`;
|
||||
} else {
|
||||
requestURL += `?api_key=${key}`;
|
||||
requestURL.searchParams.append('api_key', key);
|
||||
}
|
||||
|
||||
if (appendToResponse) {
|
||||
requestURL.searchParams.append('append_to_response', appendToResponse);
|
||||
}
|
||||
|
||||
return fetch(requestURL, {
|
||||
@@ -29,7 +33,7 @@ export async function makeTMDBRequest(url: string): Promise<Response> {
|
||||
}
|
||||
|
||||
export async function getMovieMediaDetails(id: string): Promise<MovieMedia> {
|
||||
const response = await makeTMDBRequest(`https://api.themoviedb.org/3/movie/${id}`);
|
||||
const response = await makeTMDBRequest(`https://api.themoviedb.org/3/movie/${id}`, 'external_ids');
|
||||
const movie = await response.json();
|
||||
|
||||
if (movie.success === false) {
|
||||
@@ -45,13 +49,14 @@ export async function getMovieMediaDetails(id: string): Promise<MovieMedia> {
|
||||
title: movie.title,
|
||||
releaseYear: Number(movie.release_date.split('-')[0]),
|
||||
tmdbId: id,
|
||||
imdbId: movie.imdb_id,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getShowMediaDetails(id: string, seasonNumber: string, episodeNumber: string): Promise<ShowMedia> {
|
||||
// * TV shows require the TMDB ID for the series, season, and episode
|
||||
// * and the name of the series. Needs multiple requests
|
||||
let response = await makeTMDBRequest(`https://api.themoviedb.org/3/tv/${id}`);
|
||||
let response = await makeTMDBRequest(`https://api.themoviedb.org/3/tv/${id}`, 'external_ids');
|
||||
const series = await response.json();
|
||||
|
||||
if (series.success === false) {
|
||||
@@ -91,5 +96,6 @@ export async function getShowMediaDetails(id: string, seasonNumber: string, epis
|
||||
number: season.season_number,
|
||||
tmdbId: season.id,
|
||||
},
|
||||
imdbId: series.external_ids.imdb_id,
|
||||
};
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@ const headerMap: Record<string, string> = {
|
||||
cookie: 'X-Cookie',
|
||||
referer: 'X-Referer',
|
||||
origin: 'X-Origin',
|
||||
'user-agent': 'X-User-Agent',
|
||||
'x-real-ip': 'X-X-Real-Ip',
|
||||
};
|
||||
|
||||
const responseHeaderMap: Record<string, string> = {
|
||||
|
@@ -4,7 +4,7 @@ export type FetcherOptions = {
|
||||
baseUrl?: string;
|
||||
headers?: Record<string, string>;
|
||||
query?: Record<string, string>;
|
||||
method?: 'GET' | 'POST';
|
||||
method?: 'HEAD' | 'GET' | 'POST';
|
||||
readHeaders?: string[];
|
||||
body?: Record<string, any> | string | FormData | URLSearchParams;
|
||||
};
|
||||
@@ -17,7 +17,7 @@ export type DefaultedFetcherOptions = {
|
||||
headers: Record<string, string>;
|
||||
query: Record<string, string>;
|
||||
readHeaders: string[];
|
||||
method: 'GET' | 'POST';
|
||||
method: 'HEAD' | 'GET' | 'POST';
|
||||
};
|
||||
|
||||
export type FetcherResponse<T = any> = {
|
||||
|
@@ -3,20 +3,26 @@ import { febboxHlsScraper } from '@/providers/embeds/febbox/hls';
|
||||
import { febboxMp4Scraper } from '@/providers/embeds/febbox/mp4';
|
||||
import { mixdropScraper } from '@/providers/embeds/mixdrop';
|
||||
import { mp4uploadScraper } from '@/providers/embeds/mp4upload';
|
||||
import { streambucketScraper } from '@/providers/embeds/streambucket';
|
||||
import { streamsbScraper } from '@/providers/embeds/streamsb';
|
||||
import { upcloudScraper } from '@/providers/embeds/upcloud';
|
||||
import { upstreamScraper } from '@/providers/embeds/upstream';
|
||||
import { vidsrcembedScraper } from '@/providers/embeds/vidsrc';
|
||||
import { flixhqScraper } from '@/providers/sources/flixhq/index';
|
||||
import { goMoviesScraper } from '@/providers/sources/gomovies/index';
|
||||
import { kissAsianScraper } from '@/providers/sources/kissasian/index';
|
||||
import { lookmovieScraper } from '@/providers/sources/lookmovie';
|
||||
import { remotestreamScraper } from '@/providers/sources/remotestream';
|
||||
import { showboxScraper } from '@/providers/sources/showbox/index';
|
||||
import { vidsrcScraper } from '@/providers/sources/vidsrc/index';
|
||||
import { zoechipScraper } from '@/providers/sources/zoechip';
|
||||
|
||||
import { fileMoonScraper } from './embeds/filemoon';
|
||||
import { smashyStreamDScraper } from './embeds/smashystream/dued';
|
||||
import { smashyStreamFScraper } from './embeds/smashystream/video1';
|
||||
import { vidplayScraper } from './embeds/vidplay';
|
||||
import { smashyStreamScraper } from './sources/smashystream';
|
||||
import { vidSrcToScraper } from './sources/vidsrcto';
|
||||
|
||||
export function gatherAllSources(): Array<Sourcerer> {
|
||||
// all sources are gathered here
|
||||
@@ -27,8 +33,10 @@ export function gatherAllSources(): Array<Sourcerer> {
|
||||
showboxScraper,
|
||||
goMoviesScraper,
|
||||
zoechipScraper,
|
||||
vidsrcScraper,
|
||||
lookmovieScraper,
|
||||
smashyStreamScraper,
|
||||
vidSrcToScraper,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -42,7 +50,11 @@ export function gatherAllEmbeds(): Array<Embed> {
|
||||
febboxMp4Scraper,
|
||||
febboxHlsScraper,
|
||||
mixdropScraper,
|
||||
vidsrcembedScraper,
|
||||
streambucketScraper,
|
||||
smashyStreamFScraper,
|
||||
smashyStreamDScraper,
|
||||
fileMoonScraper,
|
||||
vidplayScraper,
|
||||
];
|
||||
}
|
||||
|
@@ -31,3 +31,13 @@ export function isValidLanguageCode(code: string | null): boolean {
|
||||
if (!code) return false;
|
||||
return ISO6391.validate(code);
|
||||
}
|
||||
|
||||
export function removeDuplicatedLanguages(list: Caption[]) {
|
||||
const beenSeen: Record<string, true> = {};
|
||||
|
||||
return list.filter((sub) => {
|
||||
if (beenSeen[sub.language]) return false;
|
||||
beenSeen[sub.language] = true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@@ -1,4 +1,9 @@
|
||||
import { Caption, getCaptionTypeFromUrl, isValidLanguageCode } from '@/providers/captions';
|
||||
import {
|
||||
Caption,
|
||||
getCaptionTypeFromUrl,
|
||||
isValidLanguageCode,
|
||||
removeDuplicatedLanguages as removeDuplicateLanguages,
|
||||
} from '@/providers/captions';
|
||||
import { captionsDomains } from '@/providers/sources/showbox/common';
|
||||
import { sendRequest } from '@/providers/sources/showbox/sendRequest';
|
||||
import { ScrapeContext } from '@/utils/context';
|
||||
@@ -36,8 +41,7 @@ export async function getSubtitles(
|
||||
|
||||
const subResult = (await sendRequest(ctx, subtitleApiQuery)) as CaptionApiResponse;
|
||||
const subtitleList = subResult.data.list;
|
||||
const output: Caption[] = [];
|
||||
const languagesAdded: Record<string, true> = {};
|
||||
let output: Caption[] = [];
|
||||
|
||||
subtitleList.forEach((sub) => {
|
||||
const subtitle = sub.subtitles.sort((a, b) => b.order - a.order)[0];
|
||||
@@ -56,9 +60,6 @@ export async function getSubtitles(
|
||||
const validCode = isValidLanguageCode(subtitle.lang);
|
||||
if (!validCode) return;
|
||||
|
||||
if (languagesAdded[subtitle.lang]) return;
|
||||
languagesAdded[subtitle.lang] = true;
|
||||
|
||||
output.push({
|
||||
id: subtitleFilePath,
|
||||
language: subtitle.lang,
|
||||
@@ -68,5 +69,7 @@ export async function getSubtitles(
|
||||
});
|
||||
});
|
||||
|
||||
output = removeDuplicateLanguages(output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
58
src/providers/embeds/filemoon/index.ts
Normal file
58
src/providers/embeds/filemoon/index.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { unpack } from 'unpacker';
|
||||
|
||||
import { SubtitleResult } from './types';
|
||||
import { makeEmbed } from '../../base';
|
||||
import { Caption, getCaptionTypeFromUrl, labelToLanguageCode } from '../../captions';
|
||||
|
||||
const evalCodeRegex = /eval\((.*)\)/g;
|
||||
const fileRegex = /file:"(.*?)"/g;
|
||||
|
||||
export const fileMoonScraper = makeEmbed({
|
||||
id: 'filemoon',
|
||||
name: 'Filemoon',
|
||||
rank: 400,
|
||||
scrape: async (ctx) => {
|
||||
const embedRes = await ctx.proxiedFetcher<string>(ctx.url, {
|
||||
headers: {
|
||||
referer: ctx.url,
|
||||
},
|
||||
});
|
||||
const evalCode = evalCodeRegex.exec(embedRes);
|
||||
if (!evalCode) throw new Error('Failed to find eval code');
|
||||
const unpacked = unpack(evalCode[1]);
|
||||
const file = fileRegex.exec(unpacked);
|
||||
if (!file?.[1]) throw new Error('Failed to find file');
|
||||
|
||||
const url = new URL(ctx.url);
|
||||
const subtitlesLink = url.searchParams.get('sub.info');
|
||||
const captions: Caption[] = [];
|
||||
if (subtitlesLink) {
|
||||
const captionsResult = await ctx.proxiedFetcher<SubtitleResult>(subtitlesLink);
|
||||
|
||||
for (const caption of captionsResult) {
|
||||
const language = labelToLanguageCode(caption.label);
|
||||
const captionType = getCaptionTypeFromUrl(caption.file);
|
||||
if (!language || !captionType) continue;
|
||||
captions.push({
|
||||
id: caption.file,
|
||||
url: caption.file,
|
||||
type: captionType,
|
||||
language,
|
||||
hasCorsRestrictions: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
stream: [
|
||||
{
|
||||
id: 'primary',
|
||||
type: 'hls',
|
||||
playlist: file[1],
|
||||
flags: [],
|
||||
captions,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
});
|
5
src/providers/embeds/filemoon/types.ts
Normal file
5
src/providers/embeds/filemoon/types.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export type SubtitleResult = {
|
||||
file: string;
|
||||
label: string;
|
||||
kind: string;
|
||||
}[];
|
101
src/providers/embeds/streambucket.ts
Normal file
101
src/providers/embeds/streambucket.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import { flags } from '@/entrypoint/utils/targets';
|
||||
import { makeEmbed } from '@/providers/base';
|
||||
|
||||
// StreamBucket makes use of https://github.com/nicxlau/hunter-php-javascript-obfuscator
|
||||
|
||||
const hunterRegex = /eval\(function\(h,u,n,t,e,r\).*?\("(.*?)",\d*?,"(.*?)",(\d*?),(\d*?),\d*?\)\)/;
|
||||
const linkRegex = /file:"(.*?)"/;
|
||||
|
||||
// This is a much more simple and optimized version of the "h,u,n,t,e,r"
|
||||
// obfuscation algorithm. It's just basic chunked+mask encoding.
|
||||
// I have seen this same encoding used on some sites under the name
|
||||
// "p,l,a,y,e,r" as well
|
||||
function decodeHunter(encoded: string, mask: string, charCodeOffset: number, delimiterOffset: number) {
|
||||
// The encoded string is made up of 'n' number of chunks.
|
||||
// Each chunk is separated by a delimiter inside the mask.
|
||||
// This offset is also used as the exponentiation base in
|
||||
// the charCode calculations
|
||||
const delimiter = mask[delimiterOffset];
|
||||
|
||||
// Split the 'encoded' string into chunks using the delimiter,
|
||||
// and filter out any empty chunks.
|
||||
const chunks = encoded.split(delimiter).filter((chunk) => chunk);
|
||||
|
||||
// Decode each chunk and concatenate the results to form the final 'decoded' string.
|
||||
const decoded = chunks
|
||||
.map((chunk) => {
|
||||
// Chunks are in reverse order. 'reduceRight' removes the
|
||||
// need to 'reverse' the array first
|
||||
const charCode = chunk.split('').reduceRight((c, value, index) => {
|
||||
// Calculate the character code for each character in the chunk.
|
||||
// This involves finding the index of 'value' in the 'mask' and
|
||||
// multiplying it by (delimiterOffset^position).
|
||||
return c + mask.indexOf(value) * delimiterOffset ** (chunk.length - 1 - index);
|
||||
}, 0);
|
||||
|
||||
// The actual character code is offset by the given amount
|
||||
return String.fromCharCode(charCode - charCodeOffset);
|
||||
})
|
||||
.join('');
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
export const streambucketScraper = makeEmbed({
|
||||
id: 'streambucket',
|
||||
name: 'StreamBucket',
|
||||
rank: 196,
|
||||
// TODO - Disabled until ctx.fetcher and ctx.proxiedFetcher don't trigger bot detection
|
||||
disabled: true,
|
||||
async scrape(ctx) {
|
||||
// Using the context fetchers make the site return just the string "No bots please!"?
|
||||
// TODO - Fix this. Native fetch does not trigger this. No idea why right now
|
||||
const response = await fetch(ctx.url);
|
||||
const html = await response.text();
|
||||
|
||||
// This is different than the above mentioned bot detection
|
||||
if (html.includes('captcha-checkbox')) {
|
||||
// TODO - This doesn't use recaptcha, just really basic "image match". Maybe could automate?
|
||||
throw new Error('StreamBucket got captchaed');
|
||||
}
|
||||
|
||||
let regexResult = html.match(hunterRegex);
|
||||
|
||||
if (!regexResult) {
|
||||
throw new Error('Failed to find StreamBucket hunter JavaScript');
|
||||
}
|
||||
|
||||
const encoded = regexResult[1];
|
||||
const mask = regexResult[2];
|
||||
const charCodeOffset = Number(regexResult[3]);
|
||||
const delimiterOffset = Number(regexResult[4]);
|
||||
|
||||
if (Number.isNaN(charCodeOffset)) {
|
||||
throw new Error('StreamBucket hunter JavaScript charCodeOffset is not a valid number');
|
||||
}
|
||||
|
||||
if (Number.isNaN(delimiterOffset)) {
|
||||
throw new Error('StreamBucket hunter JavaScript delimiterOffset is not a valid number');
|
||||
}
|
||||
|
||||
const decoded = decodeHunter(encoded, mask, charCodeOffset, delimiterOffset);
|
||||
|
||||
regexResult = decoded.match(linkRegex);
|
||||
|
||||
if (!regexResult) {
|
||||
throw new Error('Failed to find StreamBucket HLS link');
|
||||
}
|
||||
|
||||
return {
|
||||
stream: [
|
||||
{
|
||||
id: 'primary',
|
||||
type: 'hls',
|
||||
playlist: regexResult[1],
|
||||
flags: [flags.CORS_ALLOWED],
|
||||
captions: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
});
|
54
src/providers/embeds/vidplay/common.ts
Normal file
54
src/providers/embeds/vidplay/common.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { makeFullUrl } from '@/fetchers/common';
|
||||
import { decodeData } from '@/providers/sources/vidsrcto/common';
|
||||
import { EmbedScrapeContext } from '@/utils/context';
|
||||
|
||||
export const vidplayBase = 'https://vidplay.site';
|
||||
|
||||
// This file is based on https://github.com/Ciarands/vidsrc-to-resolver/blob/dffa45e726a4b944cb9af0c9e7630476c93c0213/vidsrc.py#L16
|
||||
// Full credits to @Ciarands!
|
||||
|
||||
export const getDecryptionKeys = async (ctx: EmbedScrapeContext): Promise<string[]> => {
|
||||
const res = await ctx.fetcher<string>(
|
||||
'https://raw.githubusercontent.com/Claudemirovsky/worstsource-keys/keys/keys.json',
|
||||
);
|
||||
return JSON.parse(res);
|
||||
};
|
||||
|
||||
export const getEncodedId = async (ctx: EmbedScrapeContext) => {
|
||||
const url = new URL(ctx.url);
|
||||
const id = url.pathname.replace('/e/', '');
|
||||
const keyList = await getDecryptionKeys(ctx);
|
||||
|
||||
const decodedId = decodeData(keyList[0], id);
|
||||
const encodedResult = decodeData(keyList[1], decodedId);
|
||||
const b64encoded = btoa(encodedResult);
|
||||
return b64encoded.replace('/', '_');
|
||||
};
|
||||
|
||||
export const getFuTokenKey = async (ctx: EmbedScrapeContext) => {
|
||||
const id = await getEncodedId(ctx);
|
||||
const fuTokenRes = await ctx.proxiedFetcher<string>('/futoken', {
|
||||
baseUrl: vidplayBase,
|
||||
headers: {
|
||||
referer: ctx.url,
|
||||
},
|
||||
});
|
||||
const fuKey = fuTokenRes.match(/var\s+k\s*=\s*'([^']+)'/)?.[1];
|
||||
if (!fuKey) throw new Error('No fuKey found');
|
||||
const tokens = [];
|
||||
for (let i = 0; i < id.length; i += 1) {
|
||||
tokens.push(fuKey.charCodeAt(i % fuKey.length) + id.charCodeAt(i));
|
||||
}
|
||||
return `${fuKey},${tokens.join(',')}`;
|
||||
};
|
||||
|
||||
export const getFileUrl = async (ctx: EmbedScrapeContext) => {
|
||||
const fuToken = await getFuTokenKey(ctx);
|
||||
return makeFullUrl(`/mediainfo/${fuToken}`, {
|
||||
baseUrl: vidplayBase,
|
||||
query: {
|
||||
...Object.fromEntries(new URL(ctx.url).searchParams.entries()),
|
||||
autostart: 'true',
|
||||
},
|
||||
});
|
||||
};
|
53
src/providers/embeds/vidplay/index.ts
Normal file
53
src/providers/embeds/vidplay/index.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { makeEmbed } from '@/providers/base';
|
||||
import { Caption, getCaptionTypeFromUrl, labelToLanguageCode } from '@/providers/captions';
|
||||
|
||||
import { getFileUrl } from './common';
|
||||
import { SubtitleResult, VidplaySourceResponse } from './types';
|
||||
|
||||
export const vidplayScraper = makeEmbed({
|
||||
id: 'vidplay',
|
||||
name: 'VidPlay',
|
||||
rank: 401,
|
||||
scrape: async (ctx) => {
|
||||
const fileUrl = await getFileUrl(ctx);
|
||||
const fileUrlRes = await ctx.proxiedFetcher<VidplaySourceResponse>(fileUrl, {
|
||||
headers: {
|
||||
referer: ctx.url,
|
||||
},
|
||||
});
|
||||
if (typeof fileUrlRes.result === 'number') throw new Error('File not found');
|
||||
const source = fileUrlRes.result.sources[0].file;
|
||||
|
||||
const url = new URL(ctx.url);
|
||||
const subtitlesLink = url.searchParams.get('sub.info');
|
||||
const captions: Caption[] = [];
|
||||
if (subtitlesLink) {
|
||||
const captionsResult = await ctx.proxiedFetcher<SubtitleResult>(subtitlesLink);
|
||||
|
||||
for (const caption of captionsResult) {
|
||||
const language = labelToLanguageCode(caption.label);
|
||||
const captionType = getCaptionTypeFromUrl(caption.file);
|
||||
if (!language || !captionType) continue;
|
||||
captions.push({
|
||||
id: caption.file,
|
||||
url: caption.file,
|
||||
type: captionType,
|
||||
language,
|
||||
hasCorsRestrictions: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
stream: [
|
||||
{
|
||||
id: 'primary',
|
||||
type: 'hls',
|
||||
playlist: source,
|
||||
flags: [],
|
||||
captions,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
});
|
19
src/providers/embeds/vidplay/types.ts
Normal file
19
src/providers/embeds/vidplay/types.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export type VidplaySourceResponse = {
|
||||
result:
|
||||
| {
|
||||
sources: {
|
||||
file: string;
|
||||
tracks: {
|
||||
file: string;
|
||||
kind: string;
|
||||
}[];
|
||||
}[];
|
||||
}
|
||||
| number;
|
||||
};
|
||||
|
||||
export type SubtitleResult = {
|
||||
file: string;
|
||||
label: string;
|
||||
kind: string;
|
||||
}[];
|
55
src/providers/embeds/vidsrc.ts
Normal file
55
src/providers/embeds/vidsrc.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { flags } from '@/entrypoint/utils/targets';
|
||||
import { makeEmbed } from '@/providers/base';
|
||||
|
||||
const hlsURLRegex = /file:"(.*?)"/;
|
||||
const setPassRegex = /var pass_path = "(.*set_pass\.php.*)";/;
|
||||
|
||||
export const vidsrcembedScraper = makeEmbed({
|
||||
id: 'vidsrcembed', // VidSrc is both a source and an embed host
|
||||
name: 'VidSrc',
|
||||
rank: 197,
|
||||
async scrape(ctx) {
|
||||
const html = await ctx.proxiedFetcher<string>(ctx.url, {
|
||||
headers: {
|
||||
referer: ctx.url,
|
||||
},
|
||||
});
|
||||
|
||||
const match = html
|
||||
.match(hlsURLRegex)?.[1]
|
||||
?.replace(/(\/\/\S+?=)/g, '')
|
||||
.replace('#2', '');
|
||||
if (!match) throw new Error('Unable to find HLS playlist');
|
||||
const finalUrl = atob(match);
|
||||
|
||||
if (!finalUrl.includes('.m3u8')) throw new Error('Unable to find HLS playlist');
|
||||
|
||||
let setPassLink = html.match(setPassRegex)?.[1];
|
||||
if (!setPassLink) throw new Error('Unable to find set_pass.php link');
|
||||
|
||||
if (setPassLink.startsWith('//')) {
|
||||
setPassLink = `https:${setPassLink}`;
|
||||
}
|
||||
|
||||
// VidSrc uses a password endpoint to temporarily whitelist the user's IP. This is called in an interval by the player.
|
||||
// It currently has no effect on the player itself, the content plays fine without it.
|
||||
// In the future we might have to introduce hooks for the frontend to call this endpoint.
|
||||
await ctx.proxiedFetcher(setPassLink, {
|
||||
headers: {
|
||||
referer: ctx.url,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
stream: [
|
||||
{
|
||||
id: 'primary',
|
||||
type: 'hls',
|
||||
playlist: finalUrl,
|
||||
flags: [flags.CORS_ALLOWED],
|
||||
captions: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
});
|
@@ -33,7 +33,6 @@ export const lookmovieScraper = makeSourcerer({
|
||||
id: 'lookmovie',
|
||||
name: 'LookMovie',
|
||||
rank: 1,
|
||||
disabled: true,
|
||||
flags: [flags.IP_LOCKED],
|
||||
scrapeShow: universalScraper,
|
||||
scrapeMovie: universalScraper,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media';
|
||||
import { Caption } from '@/providers/captions';
|
||||
import { Caption, labelToLanguageCode, removeDuplicatedLanguages } from '@/providers/captions';
|
||||
import { ScrapeContext } from '@/utils/context';
|
||||
|
||||
import { StreamsDataResult } from './type';
|
||||
@@ -44,13 +44,21 @@ export async function getVideo(
|
||||
}
|
||||
}
|
||||
|
||||
const captions: Caption[] = data.subtitles.map((sub) => ({
|
||||
id: sub.url,
|
||||
type: 'vtt',
|
||||
url: `${baseUrl}${sub.url}`,
|
||||
hasCorsRestrictions: false,
|
||||
language: sub.language,
|
||||
}));
|
||||
let captions: Caption[] = [];
|
||||
|
||||
for (const sub of data.subtitles) {
|
||||
const language = labelToLanguageCode(sub.language);
|
||||
if (!language) continue;
|
||||
captions.push({
|
||||
id: sub.url,
|
||||
type: 'vtt',
|
||||
url: `${baseUrl}${sub.url}`,
|
||||
hasCorsRestrictions: false,
|
||||
language,
|
||||
});
|
||||
}
|
||||
|
||||
captions = removeDuplicatedLanguages(captions);
|
||||
|
||||
return {
|
||||
playlist: videoUrl,
|
||||
|
@@ -2,7 +2,7 @@ import { flags } from '@/entrypoint/utils/targets';
|
||||
import { makeSourcerer } from '@/providers/base';
|
||||
import { NotFoundError } from '@/utils/errors';
|
||||
|
||||
const remotestreamBase = `https://fsa.remotestre.am`;
|
||||
const remotestreamBase = atob('aHR0cHM6Ly9mc2IuOG1ldDNkdGpmcmNxY2hjb25xcGtsd3hzeGIyb2N1bWMuc3RyZWFt');
|
||||
|
||||
export const remotestreamScraper = makeSourcerer({
|
||||
id: 'remotestream',
|
||||
@@ -16,8 +16,12 @@ export const remotestreamScraper = makeSourcerer({
|
||||
const playlistLink = `${remotestreamBase}/Shows/${ctx.media.tmdbId}/${seasonNumber}/${episodeNumber}/${episodeNumber}.m3u8`;
|
||||
|
||||
ctx.progress(30);
|
||||
const streamRes = await ctx.fetcher<Blob>(playlistLink); // TODO support blobs in fetchers
|
||||
if (streamRes.type !== 'application/x-mpegurl') throw new NotFoundError('No watchable item found');
|
||||
const streamRes = await ctx.fetcher.full(playlistLink, {
|
||||
method: 'HEAD',
|
||||
readHeaders: ['content-type'],
|
||||
});
|
||||
if (!streamRes.headers.get('content-type')?.toLowerCase().includes('application/x-mpegurl'))
|
||||
throw new NotFoundError('No watchable item found');
|
||||
ctx.progress(90);
|
||||
|
||||
return {
|
||||
@@ -37,8 +41,12 @@ export const remotestreamScraper = makeSourcerer({
|
||||
const playlistLink = `${remotestreamBase}/Movies/${ctx.media.tmdbId}/${ctx.media.tmdbId}.m3u8`;
|
||||
|
||||
ctx.progress(30);
|
||||
const streamRes = await ctx.fetcher<Blob>(playlistLink);
|
||||
if (streamRes.type !== 'application/x-mpegurl') throw new NotFoundError('No watchable item found');
|
||||
const streamRes = await ctx.fetcher.full(playlistLink, {
|
||||
method: 'HEAD',
|
||||
readHeaders: ['content-type'],
|
||||
});
|
||||
if (!streamRes.headers.get('content-type')?.toLowerCase().includes('application/x-mpegurl'))
|
||||
throw new NotFoundError('No watchable item found');
|
||||
ctx.progress(90);
|
||||
|
||||
return {
|
||||
|
@@ -49,9 +49,9 @@ export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = fal
|
||||
headers: {
|
||||
Platform: 'android',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'User-Agent': 'okhttp/3.2.0',
|
||||
},
|
||||
body: formatted,
|
||||
});
|
||||
|
||||
return JSON.parse(response);
|
||||
};
|
||||
|
2
src/providers/sources/vidsrc/common.ts
Normal file
2
src/providers/sources/vidsrc/common.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export const vidsrcBase = 'https://vidsrc.me';
|
||||
export const vidsrcRCPBase = 'https://rcp.vidsrc.me';
|
13
src/providers/sources/vidsrc/index.ts
Normal file
13
src/providers/sources/vidsrc/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { flags } from '@/entrypoint/utils/targets';
|
||||
import { makeSourcerer } from '@/providers/base';
|
||||
import { scrapeMovie } from '@/providers/sources/vidsrc/scrape-movie';
|
||||
import { scrapeShow } from '@/providers/sources/vidsrc/scrape-show';
|
||||
|
||||
export const vidsrcScraper = makeSourcerer({
|
||||
id: 'vidsrc',
|
||||
name: 'VidSrc',
|
||||
rank: 120,
|
||||
flags: [flags.CORS_ALLOWED],
|
||||
scrapeMovie,
|
||||
scrapeShow,
|
||||
});
|
8
src/providers/sources/vidsrc/scrape-movie.ts
Normal file
8
src/providers/sources/vidsrc/scrape-movie.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { getVidSrcMovieSources } from '@/providers/sources/vidsrc/scrape';
|
||||
import { MovieScrapeContext } from '@/utils/context';
|
||||
|
||||
export async function scrapeMovie(ctx: MovieScrapeContext) {
|
||||
return {
|
||||
embeds: await getVidSrcMovieSources(ctx),
|
||||
};
|
||||
}
|
8
src/providers/sources/vidsrc/scrape-show.ts
Normal file
8
src/providers/sources/vidsrc/scrape-show.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { getVidSrcShowSources } from '@/providers/sources/vidsrc/scrape';
|
||||
import { ShowScrapeContext } from '@/utils/context';
|
||||
|
||||
export async function scrapeShow(ctx: ShowScrapeContext) {
|
||||
return {
|
||||
embeds: await getVidSrcShowSources(ctx),
|
||||
};
|
||||
}
|
133
src/providers/sources/vidsrc/scrape.ts
Normal file
133
src/providers/sources/vidsrc/scrape.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import { load } from 'cheerio';
|
||||
|
||||
import { SourcererEmbed } from '@/providers/base';
|
||||
import { streambucketScraper } from '@/providers/embeds/streambucket';
|
||||
import { vidsrcembedScraper } from '@/providers/embeds/vidsrc';
|
||||
import { vidsrcBase, vidsrcRCPBase } from '@/providers/sources/vidsrc/common';
|
||||
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
||||
|
||||
function decodeSrc(encoded: string, seed: string) {
|
||||
let decoded = '';
|
||||
const seedLength = seed.length;
|
||||
|
||||
for (let i = 0; i < encoded.length; i += 2) {
|
||||
const byte = parseInt(encoded.substr(i, 2), 16);
|
||||
const seedChar = seed.charCodeAt((i / 2) % seedLength);
|
||||
decoded += String.fromCharCode(byte ^ seedChar);
|
||||
}
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
async function getVidSrcEmbeds(ctx: MovieScrapeContext | ShowScrapeContext, startingURL: string) {
|
||||
// VidSrc works by using hashes and a redirect system.
|
||||
// The hashes are stored in the html, and VidSrc will
|
||||
// make requests to their servers with the hash. This
|
||||
// will trigger a 302 response with a Location header
|
||||
// sending the user to the correct embed. To get the
|
||||
// real embed links, we must do the same. Slow, but
|
||||
// required
|
||||
|
||||
const embeds: SourcererEmbed[] = [];
|
||||
|
||||
let html = await ctx.proxiedFetcher<string>(startingURL, {
|
||||
baseUrl: vidsrcBase,
|
||||
});
|
||||
|
||||
let $ = load(html);
|
||||
|
||||
const sourceHashes = $('.server[data-hash]')
|
||||
.toArray()
|
||||
.map((el) => $(el).attr('data-hash'))
|
||||
.filter((hash) => hash !== undefined);
|
||||
|
||||
for (const hash of sourceHashes) {
|
||||
html = await ctx.proxiedFetcher<string>(`/rcp/${hash}`, {
|
||||
baseUrl: vidsrcRCPBase,
|
||||
headers: {
|
||||
referer: vidsrcBase,
|
||||
},
|
||||
});
|
||||
|
||||
$ = load(html);
|
||||
const encoded = $('#hidden').attr('data-h');
|
||||
const seed = $('body').attr('data-i');
|
||||
|
||||
if (!encoded || !seed) {
|
||||
throw new Error('Failed to find encoded iframe src');
|
||||
}
|
||||
|
||||
let redirectURL = decodeSrc(encoded, seed);
|
||||
if (redirectURL.startsWith('//')) {
|
||||
redirectURL = `https:${redirectURL}`;
|
||||
}
|
||||
|
||||
const { finalUrl } = await ctx.proxiedFetcher.full(redirectURL, {
|
||||
method: 'HEAD',
|
||||
headers: {
|
||||
referer: vidsrcBase,
|
||||
},
|
||||
});
|
||||
|
||||
const embed: SourcererEmbed = {
|
||||
embedId: '',
|
||||
url: finalUrl,
|
||||
};
|
||||
|
||||
const parsedUrl = new URL(finalUrl);
|
||||
|
||||
switch (parsedUrl.host) {
|
||||
case 'vidsrc.stream':
|
||||
embed.embedId = vidsrcembedScraper.id;
|
||||
break;
|
||||
case 'streambucket.net':
|
||||
embed.embedId = streambucketScraper.id;
|
||||
break;
|
||||
case '2embed.cc':
|
||||
case 'www.2embed.cc':
|
||||
// Just ignore this. This embed just sources from other embeds we can scrape as a 'source'
|
||||
break;
|
||||
case 'player-cdn.com':
|
||||
// Just ignore this. This embed streams video over a custom WebSocket connection
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Failed to find VidSrc embed source for ${finalUrl}`);
|
||||
}
|
||||
|
||||
// Since some embeds are ignored on purpose, check if a valid one was found
|
||||
if (embed.embedId !== '') {
|
||||
embeds.push(embed);
|
||||
}
|
||||
}
|
||||
|
||||
return embeds;
|
||||
}
|
||||
|
||||
export async function getVidSrcMovieSources(ctx: MovieScrapeContext) {
|
||||
return getVidSrcEmbeds(ctx, `/embed/${ctx.media.tmdbId}`);
|
||||
}
|
||||
|
||||
export async function getVidSrcShowSources(ctx: ShowScrapeContext) {
|
||||
// VidSrc will always default to season 1 episode 1
|
||||
// no matter what embed URL is used. It sends back
|
||||
// a list of ALL the shows episodes, in order, for
|
||||
// all seasons. To get the real embed URL, have to
|
||||
// parse this from the response
|
||||
const html = await ctx.proxiedFetcher<string>(`/embed/${ctx.media.tmdbId}`, {
|
||||
baseUrl: vidsrcBase,
|
||||
});
|
||||
|
||||
const $ = load(html);
|
||||
|
||||
const episodeElement = $(`.ep[data-s="${ctx.media.season.number}"][data-e="${ctx.media.episode.number}"]`).first();
|
||||
if (episodeElement.length === 0) {
|
||||
throw new Error('failed to find episode element');
|
||||
}
|
||||
|
||||
const startingURL = episodeElement.attr('data-iframe');
|
||||
if (!startingURL) {
|
||||
throw new Error('failed to find episode starting URL');
|
||||
}
|
||||
|
||||
return getVidSrcEmbeds(ctx, startingURL);
|
||||
}
|
49
src/providers/sources/vidsrcto/common.ts
Normal file
49
src/providers/sources/vidsrcto/common.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
// This file is based on https://github.com/Ciarands/vidsrc-to-resolver/blob/dffa45e726a4b944cb9af0c9e7630476c93c0213/vidsrc.py#L16
|
||||
// Full credits to @Ciarands!
|
||||
|
||||
const DECRYPTION_KEY = '8z5Ag5wgagfsOuhz';
|
||||
|
||||
export const decodeBase64UrlSafe = (str: string) => {
|
||||
const standardizedInput = str.replace(/_/g, '/').replace(/-/g, '+');
|
||||
const decodedData = atob(standardizedInput);
|
||||
|
||||
const bytes = new Uint8Array(decodedData.length);
|
||||
for (let i = 0; i < bytes.length; i += 1) {
|
||||
bytes[i] = decodedData.charCodeAt(i);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
};
|
||||
|
||||
export const decodeData = (key: string, data: any) => {
|
||||
const state = Array.from(Array(256).keys());
|
||||
let index1 = 0;
|
||||
for (let i = 0; i < 256; i += 1) {
|
||||
index1 = (index1 + state[i] + key.charCodeAt(i % key.length)) % 256;
|
||||
const temp = state[i];
|
||||
state[i] = state[index1];
|
||||
state[index1] = temp;
|
||||
}
|
||||
index1 = 0;
|
||||
let index2 = 0;
|
||||
let finalKey = '';
|
||||
for (let char = 0; char < data.length; char += 1) {
|
||||
index1 = (index1 + 1) % 256;
|
||||
index2 = (index2 + state[index1]) % 256;
|
||||
const temp = state[index1];
|
||||
state[index1] = state[index2];
|
||||
state[index2] = temp;
|
||||
if (typeof data[char] === 'string') {
|
||||
finalKey += String.fromCharCode(data[char].charCodeAt(0) ^ state[(state[index1] + state[index2]) % 256]);
|
||||
} else if (typeof data[char] === 'number') {
|
||||
finalKey += String.fromCharCode(data[char] ^ state[(state[index1] + state[index2]) % 256]);
|
||||
}
|
||||
}
|
||||
return finalKey;
|
||||
};
|
||||
|
||||
export const decryptSourceUrl = (sourceUrl: string) => {
|
||||
const encoded = decodeBase64UrlSafe(sourceUrl);
|
||||
const decoded = decodeData(DECRYPTION_KEY, encoded);
|
||||
return decodeURIComponent(decodeURIComponent(decoded));
|
||||
};
|
84
src/providers/sources/vidsrcto/index.ts
Normal file
84
src/providers/sources/vidsrcto/index.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { load } from 'cheerio';
|
||||
|
||||
import { SourcererEmbed, SourcererOutput, makeSourcerer } from '@/providers/base';
|
||||
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
||||
|
||||
import { decryptSourceUrl } from './common';
|
||||
import { SourceResult, SourcesResult } from './types';
|
||||
|
||||
const vidSrcToBase = 'https://vidsrc.to';
|
||||
const referer = `${vidSrcToBase}/`;
|
||||
|
||||
const universalScraper = async (ctx: ShowScrapeContext | MovieScrapeContext): Promise<SourcererOutput> => {
|
||||
const imdbId = ctx.media.imdbId;
|
||||
const url =
|
||||
ctx.media.type === 'movie'
|
||||
? `/embed/movie/${imdbId}`
|
||||
: `/embed/tv/${imdbId}/${ctx.media.season.number}/${ctx.media.episode.number}`;
|
||||
const mainPage = await ctx.proxiedFetcher<string>(url, {
|
||||
baseUrl: vidSrcToBase,
|
||||
headers: {
|
||||
referer,
|
||||
},
|
||||
});
|
||||
const mainPage$ = load(mainPage);
|
||||
const dataId = mainPage$('a[data-id]').attr('data-id');
|
||||
if (!dataId) throw new Error('No data-id found');
|
||||
const sources = await ctx.proxiedFetcher<SourcesResult>(`/ajax/embed/episode/${dataId}/sources`, {
|
||||
baseUrl: vidSrcToBase,
|
||||
headers: {
|
||||
referer,
|
||||
},
|
||||
});
|
||||
if (sources.status !== 200) throw new Error('No sources found');
|
||||
|
||||
const embeds: SourcererEmbed[] = [];
|
||||
const embedUrls = [];
|
||||
for (const source of sources.result) {
|
||||
const sourceRes = await ctx.proxiedFetcher<SourceResult>(`/ajax/embed/source/${source.id}`, {
|
||||
baseUrl: vidSrcToBase,
|
||||
headers: {
|
||||
referer,
|
||||
},
|
||||
});
|
||||
const decryptedUrl = decryptSourceUrl(sourceRes.result.url);
|
||||
embedUrls.push(decryptedUrl);
|
||||
}
|
||||
|
||||
// Originally Filemoon does not have subtitles. But we can use the ones from Vidplay.
|
||||
const subtitleUrl = new URL(embedUrls.find((v) => v.includes('sub.info')) ?? '').searchParams.get('sub.info');
|
||||
for (const source of sources.result) {
|
||||
if (source.title === 'Vidplay') {
|
||||
const embedUrl = embedUrls.find((v) => v.includes('vidplay'));
|
||||
if (!embedUrl) continue;
|
||||
embeds.push({
|
||||
embedId: 'vidplay',
|
||||
url: embedUrl,
|
||||
});
|
||||
}
|
||||
|
||||
if (source.title === 'Filemoon') {
|
||||
const embedUrl = embedUrls.find((v) => v.includes('filemoon'));
|
||||
if (!embedUrl) continue;
|
||||
const fullUrl = new URL(embedUrl);
|
||||
if (subtitleUrl) fullUrl.searchParams.set('sub.info', subtitleUrl);
|
||||
embeds.push({
|
||||
embedId: 'filemoon',
|
||||
url: fullUrl.toString(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
embeds,
|
||||
};
|
||||
};
|
||||
|
||||
export const vidSrcToScraper = makeSourcerer({
|
||||
id: 'vidsrcto',
|
||||
name: 'VidSrcTo',
|
||||
scrapeMovie: universalScraper,
|
||||
scrapeShow: universalScraper,
|
||||
flags: [],
|
||||
rank: 400,
|
||||
});
|
15
src/providers/sources/vidsrcto/types.ts
Normal file
15
src/providers/sources/vidsrcto/types.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export type VidSrcToResponse<T> = {
|
||||
status: number;
|
||||
result: T;
|
||||
};
|
||||
|
||||
export type SourcesResult = VidSrcToResponse<
|
||||
{
|
||||
id: string;
|
||||
title: 'Filemoon' | 'Vidplay';
|
||||
}[]
|
||||
>;
|
||||
|
||||
export type SourceResult = VidSrcToResponse<{
|
||||
url: string;
|
||||
}>;
|
Reference in New Issue
Block a user