From fa9785bf69617736d64d112be2f2d5b482891bda Mon Sep 17 00:00:00 2001 From: Jip Fr Date: Sun, 22 Jan 2023 23:06:29 +0100 Subject: [PATCH] chore(superstream): improve import, move quality finding to its own function --- src/backend/index.ts | 2 +- .../superstream/{superstream.ts => index.ts} | 38 ++++++------------- 2 files changed, 13 insertions(+), 27 deletions(-) rename src/backend/providers/superstream/{superstream.ts => index.ts} (88%) diff --git a/src/backend/index.ts b/src/backend/index.ts index 7859f2cd..5e4f7989 100644 --- a/src/backend/index.ts +++ b/src/backend/index.ts @@ -3,7 +3,7 @@ import { initializeScraperStore } from "./helpers/register"; // providers import "./providers/gdriveplayer"; import "./providers/flixhq"; -import "./providers/superstream/superstream"; +import "./providers/superstream"; // embeds // -- nothing here yet diff --git a/src/backend/providers/superstream/superstream.ts b/src/backend/providers/superstream/index.ts similarity index 88% rename from src/backend/providers/superstream/superstream.ts rename to src/backend/providers/superstream/index.ts index cb0c3928..aaf460b0 100644 --- a/src/backend/providers/superstream/superstream.ts +++ b/src/backend/providers/superstream/index.ts @@ -98,6 +98,16 @@ const get = (data: object, altApi = false) => { }); }; +// Find best resolution +const getBestQuality = (list: any[]) => { + return ( + list.find((quality: any) => quality.quality === "1080p" && quality.path) ?? + list.find((quality: any) => quality.quality === "720p" && quality.path) ?? + list.find((quality: any) => quality.quality === "480p" && quality.path) ?? + list.find((quality: any) => quality.quality === "360p" && quality.path) + ); +}; + registerProvider({ id: "superstream", displayName: "Superstream", @@ -138,19 +148,7 @@ registerProvider({ const mediaRes = (await get(apiQuery)).data; progress(50); - const hdQuality = - mediaRes.list.find( - (quality: any) => quality.quality === "1080p" && quality.path - ) ?? - mediaRes.list.find( - (quality: any) => quality.quality === "720p" && quality.path - ) ?? - mediaRes.list.find( - (quality: any) => quality.quality === "480p" && quality.path - ) ?? - mediaRes.list.find( - (quality: any) => quality.quality === "360p" && quality.path - ); + const hdQuality = getBestQuality(mediaRes.list); if (!hdQuality) throw new Error("No quality could be found."); @@ -210,19 +208,7 @@ registerProvider({ const mediaRes = (await get(apiQuery)).data; progress(66); - const hdQuality = - mediaRes.list.find( - (quality: any) => quality.quality === "1080p" && quality.path - ) ?? - mediaRes.list.find( - (quality: any) => quality.quality === "720p" && quality.path - ) ?? - mediaRes.list.find( - (quality: any) => quality.quality === "480p" && quality.path - ) ?? - mediaRes.list.find( - (quality: any) => quality.quality === "360p" && quality.path - ); + const hdQuality = getBestQuality(mediaRes.list); if (!hdQuality) throw new Error("No quality could be found.");