diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx
index 5c8fcd00..161d091b 100644
--- a/src/components/media/MediaCard.tsx
+++ b/src/components/media/MediaCard.tsx
@@ -82,7 +82,7 @@ function MediaCardContent({
export function MediaCard(props: MediaCardProps) {
let link = "movie";
- if (props.media.mediaType === MWMediaType.MOVIE) link = "series";
+ if (props.media.mediaType === MWMediaType.SERIES) link = "series";
const content = ;
diff --git a/src/providers/index.ts b/src/providers/index.ts
index 13342bf2..e967a80c 100644
--- a/src/providers/index.ts
+++ b/src/providers/index.ts
@@ -1,6 +1,13 @@
+import Fuse from "fuse.js";
import { tempScraper } from "./list/temp";
import { theFlixScraper } from "./list/theflix";
-import { MWMassProviderOutput, MWMedia, MWMediaType, MWPortableMedia, MWQuery } from "./types";
+import {
+ MWMassProviderOutput,
+ MWMedia,
+ MWMediaType,
+ MWPortableMedia,
+ MWQuery,
+} from "./types";
import { MWWrappedMediaProvider, WrapProvider } from "./wrapper";
export * from "./types";
@@ -21,35 +28,46 @@ export function GetProvidersForType(type: MWMediaType) {
/*
** Call search on all providers that matches query type
*/
-export async function SearchProviders(query: MWQuery): Promise {
- const allQueries = GetProvidersForType(query.type).map>(async (provider) => {
+export async function SearchProviders(
+ query: MWQuery
+): Promise {
+ const allQueries = GetProvidersForType(query.type).map<
+ Promise<{ media: MWMedia[]; success: boolean; id: string }>
+ >(async (provider) => {
try {
return {
media: await provider.searchForMedia(query),
success: true,
id: provider.id,
- }
+ };
} catch (err) {
console.error(`Failed running provider ${provider.id}`, err, query);
return {
media: [],
success: false,
id: provider.id,
- }
+ };
}
});
const allResults = await Promise.all(allQueries);
- const providerResults = allResults.map(provider => ({ success: provider.success, id: provider.id }));
+ const providerResults = allResults.map((provider) => ({
+ success: provider.success,
+ id: provider.id,
+ }));
const output = {
results: allResults.flatMap((results) => results.media),
providers: providerResults,
stats: {
total: providerResults.length,
- failed: providerResults.filter(v=>!v.success).length,
- succeeded: providerResults.filter(v=>v.success).length,
+ failed: providerResults.filter((v) => !v.success).length,
+ succeeded: providerResults.filter((v) => v.success).length,
},
};
+ // sort results
+ const fuse = new Fuse(output.results, { threshold: 0.3, keys: ["title"] });
+ output.results = fuse.search(query.searchQuery).map((v) => v.item);
+
if (output.stats.total === output.stats.failed)
throw new Error("All Scrapers failed");
return output;