mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 18:13:25 +00:00
Add better embed testing + add everything
This commit is contained in:
90
src/__test__/providers/embedUtils.ts
Normal file
90
src/__test__/providers/embedUtils.ts
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import { buildProviders } from "@/entrypoint/builder";
|
||||||
|
import { ScrapeMedia } from "@/entrypoint/utils/media";
|
||||||
|
import { targets } from "@/entrypoint/utils/targets";
|
||||||
|
import { makeStandardFetcher } from "@/fetchers/standardFetch";
|
||||||
|
import { Embed, Sourcerer, SourcererEmbed } from "@/providers/base";
|
||||||
|
import { TestTypes } from "./providerUtils";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { ProviderControls } from "@/entrypoint/controls";
|
||||||
|
import { makeSimpleProxyFetcher } from "@/fetchers/simpleProxy";
|
||||||
|
|
||||||
|
export interface TestEmbedOptions {
|
||||||
|
embed: Embed;
|
||||||
|
source: Sourcerer;
|
||||||
|
testSuite: ScrapeMedia[];
|
||||||
|
types: TestTypes[];
|
||||||
|
debug?: boolean;
|
||||||
|
expect: {
|
||||||
|
embeds: number;
|
||||||
|
streams?: number;
|
||||||
|
error?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeBaseEmbedProviders() {
|
||||||
|
const builder = buildProviders()
|
||||||
|
.setTarget(targets.ANY)
|
||||||
|
.setFetcher(makeStandardFetcher(fetch));
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function testEmbed(ops: TestEmbedOptions) {
|
||||||
|
if (ops.testSuite.length === 0) throw new Error("Test suite must have at least one test");
|
||||||
|
describe(`embed:${ops.source.id}:${ops.embed.id}`, () => {
|
||||||
|
ops.testSuite.forEach((test) => {
|
||||||
|
describe(`test ${test.title}`, async () => {
|
||||||
|
async function gatherEmbeds(providers: ProviderControls): Promise<SourcererEmbed[]> {
|
||||||
|
const results = await providers.runSourceScraper({
|
||||||
|
id: ops.source.id,
|
||||||
|
media: test,
|
||||||
|
})
|
||||||
|
if (results.embeds.length !== ops.expect.embeds) throw new Error(`Embeds don't match expected amount of embeds (${ops.source.id}, ${ops.embed.id}, got ${results.embeds.length} but expected ${ops.expect.embeds})`);
|
||||||
|
return results.embeds;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runTest(providers: ProviderControls, embedUrl: string) {
|
||||||
|
let hasError = false;
|
||||||
|
let streamCount = 0;
|
||||||
|
try {
|
||||||
|
const result = await providers.runEmbedScraper({
|
||||||
|
id: ops.embed.id,
|
||||||
|
url: embedUrl,
|
||||||
|
})
|
||||||
|
if (ops.debug) console.log(result);
|
||||||
|
streamCount = (result.stream ?? []).length;
|
||||||
|
} catch (err) {
|
||||||
|
if (ops.debug) console.log(err);
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
|
expect(ops.expect.error ?? false).toBe(hasError);
|
||||||
|
expect(ops.expect.streams ?? 0).toBe(streamCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const t of ops.types) {
|
||||||
|
const builder = makeBaseEmbedProviders().addSource(ops.source).addEmbed(ops.embed);
|
||||||
|
if (t === 'standard') {}
|
||||||
|
else if (t === 'ip:standard')
|
||||||
|
builder.enableConsistentIpForRequests();
|
||||||
|
else if (t === 'proxied') {
|
||||||
|
if (!process.env.MOVIE_WEB_PROXY_URL)
|
||||||
|
throw new Error("Cant use proxied test without setting MOVIE_WEB_PROXY_URL env");
|
||||||
|
builder.setProxiedFetcher(makeSimpleProxyFetcher(process.env.MOVIE_WEB_PROXY_URL, fetch));
|
||||||
|
}
|
||||||
|
const providers = builder.build();
|
||||||
|
try {
|
||||||
|
const embeds = await gatherEmbeds(providers);
|
||||||
|
embeds.forEach((embed, i) => {
|
||||||
|
it(`${t} - embed ${i}`, async () => {
|
||||||
|
await runTest(providers, embed.url);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
it(`${t} - embed ??`, () => {
|
||||||
|
throw new Error("Failed to get streams: " + err);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
@@ -1,17 +1,118 @@
|
|||||||
import { febboxMp4Scraper } from "@/providers/embeds/febbox/mp4";
|
|
||||||
import { testEmbed } from "./providerUtils";
|
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
import { febboxMp4Scraper } from "@/providers/embeds/febbox/mp4";
|
||||||
|
import { testEmbed } from "./embedUtils";
|
||||||
|
import { showboxScraper } from "@/providers/sources/showbox";
|
||||||
|
import { testMedia } from "./testMedia";
|
||||||
|
import { flixhqScraper } from "@/providers/sources/flixhq";
|
||||||
|
import { upcloudScraper } from "@/providers/embeds/upcloud";
|
||||||
|
import { goMoviesScraper } from "@/providers/sources/gomovies";
|
||||||
|
import { smashyStreamScraper } from "@/providers/sources/smashystream";
|
||||||
|
import { smashyStreamDScraper } from "@/providers/embeds/smashystream/dued";
|
||||||
|
import { vidsrcembedScraper } from '@/providers/embeds/vidsrc';
|
||||||
|
import { vidsrcScraper } from '@/providers/sources/vidsrc';
|
||||||
|
import { vidSrcToScraper } from '@/providers/sources/vidsrcto';
|
||||||
|
import { vidplayScraper } from '@/providers/embeds/vidplay';
|
||||||
|
import { fileMoonScraper } from '@/providers/embeds/filemoon';
|
||||||
|
import { zoechipScraper } from '@/providers/sources/zoechip';
|
||||||
|
import { mixdropScraper } from '@/providers/embeds/mixdrop';
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
testEmbed({
|
testEmbed({
|
||||||
embed: febboxMp4Scraper,
|
embed: febboxMp4Scraper,
|
||||||
testUrls: [
|
source: showboxScraper,
|
||||||
'/show/16448/1/1',
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
'/movie/27769//'
|
|
||||||
],
|
|
||||||
types: ['standard', 'proxied'],
|
types: ['standard', 'proxied'],
|
||||||
expect: {
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testEmbed({
|
||||||
|
embed: upcloudScraper,
|
||||||
|
source: flixhqScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testEmbed({
|
||||||
|
embed: upcloudScraper,
|
||||||
|
source: goMoviesScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testEmbed({
|
||||||
|
embed: smashyStreamDScraper,
|
||||||
|
source: smashyStreamScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testEmbed({
|
||||||
|
embed: vidsrcembedScraper,
|
||||||
|
source: vidsrcScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testEmbed({
|
||||||
|
embed: vidplayScraper,
|
||||||
|
source: vidSrcToScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testEmbed({
|
||||||
|
embed: fileMoonScraper,
|
||||||
|
source: vidSrcToScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testEmbed({
|
||||||
|
embed: upcloudScraper,
|
||||||
|
source: zoechipScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 2,
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testEmbed({
|
||||||
|
embed: mixdropScraper,
|
||||||
|
source: zoechipScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 2,
|
||||||
streams: 1,
|
streams: 1,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { ScrapeMedia } from "@/entrypoint/utils/media";
|
import { ScrapeMedia } from "@/entrypoint/utils/media";
|
||||||
import { Embed, Sourcerer } from "@/providers/base";
|
import { Embed, Sourcerer, SourcererEmbed } from "@/providers/base";
|
||||||
import { buildProviders } from "@/entrypoint/builder";
|
import { buildProviders } from "@/entrypoint/builder";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { makeStandardFetcher } from "@/fetchers/standardFetch";
|
import { makeStandardFetcher } from "@/fetchers/standardFetch";
|
||||||
@@ -24,41 +24,26 @@ export interface TestSourceOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TestEmbedOptions {
|
|
||||||
embed: Embed;
|
|
||||||
testUrls: string[];
|
|
||||||
types: TestTypes[];
|
|
||||||
debug?: boolean;
|
|
||||||
expect: {
|
|
||||||
streams?: number;
|
|
||||||
error?: boolean;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeBaseProviders() {
|
function makeBaseProviders() {
|
||||||
const builder = makeBaseEmbedProviders();
|
|
||||||
const embeds = getBuiltinEmbeds();
|
|
||||||
embeds.forEach(embed => builder.addEmbed(embed));
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeBaseEmbedProviders() {
|
|
||||||
const builder = buildProviders()
|
const builder = buildProviders()
|
||||||
.setTarget(targets.ANY)
|
.setTarget(targets.ANY)
|
||||||
.setFetcher(makeStandardFetcher(fetch));
|
.setFetcher(makeStandardFetcher(fetch));
|
||||||
|
const embeds = getBuiltinEmbeds();
|
||||||
|
embeds.forEach(embed => builder.addEmbed(embed));
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function testSource(ops: TestSourceOptions) {
|
export function testSource(ops: TestSourceOptions) {
|
||||||
if (ops.testSuite.length === 0) throw new Error("Test suite must have at least one test");
|
if (ops.testSuite.length === 0) throw new Error("Test suite must have at least one test");
|
||||||
describe(`source:${ops.source.id}`, () => {
|
describe(`source:${ops.source.id}`, () => {
|
||||||
ops.testSuite.forEach((test, i) => {
|
ops.testSuite.forEach((test) => {
|
||||||
describe(`test ${i}`, () => {
|
describe(`test ${test.title}`, () => {
|
||||||
async function runTest(providers: ProviderControls) {
|
async function runTest(providers: ProviderControls) {
|
||||||
let hasNotFound = false;
|
let hasNotFound = false;
|
||||||
let hasError = false;
|
let hasError = false;
|
||||||
let streamCount = 0;
|
let streamCount = 0;
|
||||||
let embedCount = 0;
|
let embedCount = 0;
|
||||||
|
let embeds = [];
|
||||||
try {
|
try {
|
||||||
const result = await providers.runSourceScraper({
|
const result = await providers.runSourceScraper({
|
||||||
id: ops.source.id,
|
id: ops.source.id,
|
||||||
@@ -115,61 +100,3 @@ export function testSource(ops: TestSourceOptions) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function testEmbed(ops: TestEmbedOptions) {
|
|
||||||
if (ops.testUrls.length === 0) throw new Error("Test urls must have at least one url");
|
|
||||||
describe(`embed:${ops.embed.id}`, () => {
|
|
||||||
ops.testUrls.forEach((test, i) => {
|
|
||||||
describe(`test ${i}`, () => {
|
|
||||||
async function runTest(providers: ProviderControls) {
|
|
||||||
let hasError = false;
|
|
||||||
let streamCount = 0;
|
|
||||||
try {
|
|
||||||
const result = await providers.runEmbedScraper({
|
|
||||||
id: ops.embed.id,
|
|
||||||
url: test,
|
|
||||||
})
|
|
||||||
if (ops.debug) console.log(result);
|
|
||||||
streamCount = (result.stream ?? []).length;
|
|
||||||
} catch (err) {
|
|
||||||
if (ops.debug) console.log(err);
|
|
||||||
hasError = true;
|
|
||||||
}
|
|
||||||
expect(ops.expect.error ?? false).toBe(hasError);
|
|
||||||
expect(ops.expect.streams ?? 0).toBe(streamCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ops.types.includes('standard')) {
|
|
||||||
it(`standard`, async () => {
|
|
||||||
const providers = makeBaseEmbedProviders()
|
|
||||||
.addEmbed(ops.embed)
|
|
||||||
.build();
|
|
||||||
await runTest(providers);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ops.types.includes('ip:standard')) {
|
|
||||||
it(`standard:ip`, async () => {
|
|
||||||
const providers = makeBaseEmbedProviders()
|
|
||||||
.addEmbed(ops.embed)
|
|
||||||
.enableConsistentIpForRequests()
|
|
||||||
.build();
|
|
||||||
await runTest(providers);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ops.types.includes('proxied')) {
|
|
||||||
it(`proxied`, async () => {
|
|
||||||
if (!process.env.MOVIE_WEB_PROXY_URL)
|
|
||||||
throw new Error("Cant use proxied test without setting MOVIE_WEB_PROXY_URL env");
|
|
||||||
const providers = makeBaseEmbedProviders()
|
|
||||||
.addEmbed(ops.embed)
|
|
||||||
.setProxiedFetcher(makeSimpleProxyFetcher(process.env.MOVIE_WEB_PROXY_URL, fetch))
|
|
||||||
.build();
|
|
||||||
await runTest(providers);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@@ -3,6 +3,13 @@ import { lookmovieScraper } from "@/providers/sources/lookmovie";
|
|||||||
import { testMedia } from "./testMedia";
|
import { testMedia } from "./testMedia";
|
||||||
import { showboxScraper } from "@/providers/sources/showbox";
|
import { showboxScraper } from "@/providers/sources/showbox";
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
import { flixhqScraper } from "@/providers/sources/flixhq";
|
||||||
|
import { goMoviesScraper } from "@/providers/sources/gomovies";
|
||||||
|
import { smashyStreamScraper } from "@/providers/sources/smashystream";
|
||||||
|
import { vidsrcScraper } from "@/providers/sources/vidsrc";
|
||||||
|
import { vidSrcToScraper } from "@/providers/sources/vidsrcto";
|
||||||
|
import { zoechipScraper } from "@/providers/sources/zoechip";
|
||||||
|
import { remotestreamScraper } from "@/providers/sources/remotestream";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@@ -23,3 +30,66 @@ testSource({
|
|||||||
embeds: 1,
|
embeds: 1,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
testSource({
|
||||||
|
source: flixhqScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testSource({
|
||||||
|
source: goMoviesScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testSource({
|
||||||
|
source: smashyStreamScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testSource({
|
||||||
|
source: vidsrcScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testSource({
|
||||||
|
source: vidSrcToScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 2,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testSource({
|
||||||
|
source: zoechipScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
embeds: 3,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testSource({
|
||||||
|
source: remotestreamScraper,
|
||||||
|
testSuite: [testMedia.arcane, testMedia.hamilton],
|
||||||
|
types: ['standard', 'proxied'],
|
||||||
|
expect: {
|
||||||
|
streams: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Reference in New Issue
Block a user