mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-30 16:17:41 +01:00
fuzzy matching for title
Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
This commit is contained in:
parent
18b7619328
commit
4d4626806d
3 changed files with 11 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import { compareTitle } from "@/utils/titleMatch";
|
||||||
import { proxiedFetch } from "../helpers/fetch";
|
import { proxiedFetch } from "../helpers/fetch";
|
||||||
import { registerProvider } from "../helpers/register";
|
import { registerProvider } from "../helpers/register";
|
||||||
import { MWStreamQuality, MWStreamType } from "../helpers/streams";
|
import { MWStreamQuality, MWStreamType } from "../helpers/streams";
|
||||||
|
@ -19,9 +20,8 @@ registerProvider({
|
||||||
baseURL: flixHqBase,
|
baseURL: flixHqBase,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// TODO fuzzy match or normalize title before comparison
|
|
||||||
const foundItem = searchResults.results.find((v: any) => {
|
const foundItem = searchResults.results.find((v: any) => {
|
||||||
return v.title === media.meta.title && v.releaseDate === media.meta.year;
|
return compareTitle(v.title, media.meta.title) && v.releaseDate === media.meta.year;
|
||||||
});
|
});
|
||||||
if (!foundItem) throw new Error("No watchable item found");
|
if (!foundItem) throw new Error("No watchable item found");
|
||||||
const flixId = foundItem.id;
|
const flixId = foundItem.id;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
MWStreamQuality,
|
MWStreamQuality,
|
||||||
MWStreamType,
|
MWStreamType,
|
||||||
} from "@/backend/helpers/streams";
|
} from "@/backend/helpers/streams";
|
||||||
|
import { compareTitle } from "@/utils/titleMatch";
|
||||||
|
|
||||||
const nanoid = customAlphabet("0123456789abcdef", 32);
|
const nanoid = customAlphabet("0123456789abcdef", 32);
|
||||||
|
|
||||||
|
@ -128,10 +129,9 @@ registerProvider({
|
||||||
const searchRes = (await get(searchQuery, true)).data;
|
const searchRes = (await get(searchQuery, true)).data;
|
||||||
progress(33);
|
progress(33);
|
||||||
|
|
||||||
// TODO: add fuzzy search and normalise strings before matching
|
|
||||||
const superstreamEntry = searchRes.find(
|
const superstreamEntry = searchRes.find(
|
||||||
(res: any) =>
|
(res: any) =>
|
||||||
res.title === media.meta.title && res.year === Number(media.meta.year)
|
compareTitle(res.title, media.meta.title) && res.year === Number(media.meta.year)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!superstreamEntry) throw new Error("No entry found on SuperStream");
|
if (!superstreamEntry) throw new Error("No entry found on SuperStream");
|
||||||
|
|
7
src/utils/titleMatch.ts
Normal file
7
src/utils/titleMatch.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
function normalizeTitle(title: string): string {
|
||||||
|
return title.trim().toLowerCase().replace(/[\'\"\:]/g, "").replace(/[^a-zA-Z0-9]+/g, "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compareTitle(a: string, b: string): boolean {
|
||||||
|
return normalizeTitle(a) === normalizeTitle(b);
|
||||||
|
}
|
Loading…
Reference in a new issue