From 391432c1ba51f2ad93dd5e83e8a104e241d0e363 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sun, 27 Aug 2023 20:57:24 +0200 Subject: [PATCH] fix flixhq scraper and organize todos --- README.md | 27 +++++++++++++++------------ src/providers/all.ts | 10 +++++----- src/providers/base.ts | 6 ++---- src/providers/sources/flixhq/index.ts | 3 ++- src/utils/predicates.ts | 4 ---- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b5fa78a..75c4979 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,19 @@ features: > This package is still WIP -> TODO documentation: examples for nodejs + browser +Todos: + - add tests (integration, unit tests) + - running individual scrapers + - finish fetchers: + - make baseUrl param work + - proper serialization (with content-type headers) for standard fetcher + - automatically parse json + - error logging for failed scrapers + - make the lib not compile into one file, keep dependency structure -> TODO documentation: how to use + usecases - -> TODO documentation: examples on how to make a custom fetcher - -> TODO functionality: running individual scrapers - -> TODO functionality: choose environment (for browser, for native) - -> TODO content: add all scrapers/providers - -> TODO tests: add tests +Future todos: + - docs: examples for nodejs + browser + - docs: how to use + usecases + - docs: examples for custom fetcher + - choose an output environment (for browser or for native) + - flixhq show support diff --git a/src/providers/all.ts b/src/providers/all.ts index b01b7e5..c2c924d 100644 --- a/src/providers/all.ts +++ b/src/providers/all.ts @@ -1,14 +1,14 @@ import { Embed, Sourcerer } from '@/providers/base'; import { upcloudScraper } from '@/providers/embeds/upcloud'; import { flixhqScraper } from '@/providers/sources/flixhq/index'; -import { hasDuplicates, isNotNull } from '@/utils/predicates'; +import { hasDuplicates } from '@/utils/predicates'; -function gatherAllSources(): Array { +function gatherAllSources(): Array { // all sources are gathered here return [flixhqScraper]; } -function gatherAllEmbeds(): Array { +function gatherAllEmbeds(): Array { // all embeds are gathered here return [upcloudScraper]; } @@ -19,8 +19,8 @@ export interface ProviderList { } export function getProviders(): ProviderList { - const sources = gatherAllSources().filter(isNotNull); - const embeds = gatherAllEmbeds().filter(isNotNull); + const sources = gatherAllSources().filter((v) => !v?.disabled); + const embeds = gatherAllEmbeds().filter((v) => !v?.disabled); const combined = [...sources, ...embeds]; const anyDuplicateId = hasDuplicates(combined.map((v) => v.id)); diff --git a/src/providers/base.ts b/src/providers/base.ts index 68c32b0..4942ffd 100644 --- a/src/providers/base.ts +++ b/src/providers/base.ts @@ -19,8 +19,7 @@ export type Sourcerer = { scrapeShow?: (input: ScrapeContext & { media: ShowMedia }) => Promise; }; -export function makeSourcerer(state: Sourcerer): Sourcerer | null { - if (state.disabled) return null; +export function makeSourcerer(state: Sourcerer): Sourcerer { return state; } @@ -36,7 +35,6 @@ export type Embed = { scrape: (input: EmbedScrapeContext) => Promise; }; -export function makeEmbed(state: Embed): Embed | null { - if (state.disabled) return null; +export function makeEmbed(state: Embed): Embed { return state; } diff --git a/src/providers/sources/flixhq/index.ts b/src/providers/sources/flixhq/index.ts index 18ceb3e..f847502 100644 --- a/src/providers/sources/flixhq/index.ts +++ b/src/providers/sources/flixhq/index.ts @@ -1,4 +1,5 @@ import { makeSourcerer } from '@/providers/base'; +import { upcloudScraper } from '@/providers/embeds/upcloud'; import { getFlixhqSourceDetails, getFlixhqSources } from '@/providers/sources/flixhq/scrape'; import { getFlixhqId } from '@/providers/sources/flixhq/search'; import { NotFoundError } from '@/utils/errors'; @@ -19,7 +20,7 @@ export const flixhqScraper = makeSourcerer({ return { embeds: [ { - embedId: '', // TODO embed id + embedId: upcloudScraper.id, url: await getFlixhqSourceDetails(ctx, upcloudStream.episodeId), }, ], diff --git a/src/utils/predicates.ts b/src/utils/predicates.ts index 03e7469..f581b2f 100644 --- a/src/utils/predicates.ts +++ b/src/utils/predicates.ts @@ -1,7 +1,3 @@ -export function isNotNull(value: T | null | undefined): value is T { - return value !== null && value !== undefined; -} - export function hasDuplicates(values: Array): boolean { return new Set(values).size !== values.length; }