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.");