mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 01:25:05 +01:00
Added fuzzy searching
Co-authored-by: James Hawkins <jhawki2005@gmail.com>
This commit is contained in:
parent
9bec456a58
commit
c763cfe0f0
@ -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 = <MediaCardContent {...props} />;
|
||||
|
||||
|
@ -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<MWMassProviderOutput> {
|
||||
const allQueries = GetProvidersForType(query.type).map<Promise<{ media: MWMedia[], success: boolean, id: string, }>>(async (provider) => {
|
||||
export async function SearchProviders(
|
||||
query: MWQuery
|
||||
): Promise<MWMassProviderOutput> {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user