mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +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 { registerProvider } from "../helpers/register";
|
||||
import { MWStreamQuality, MWStreamType } from "../helpers/streams";
|
||||
|
@ -19,9 +20,8 @@ registerProvider({
|
|||
baseURL: flixHqBase,
|
||||
}
|
||||
);
|
||||
// TODO fuzzy match or normalize title before comparison
|
||||
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");
|
||||
const flixId = foundItem.id;
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
MWStreamQuality,
|
||||
MWStreamType,
|
||||
} from "@/backend/helpers/streams";
|
||||
import { compareTitle } from "@/utils/titleMatch";
|
||||
|
||||
const nanoid = customAlphabet("0123456789abcdef", 32);
|
||||
|
||||
|
@ -128,10 +129,9 @@ registerProvider({
|
|||
const searchRes = (await get(searchQuery, true)).data;
|
||||
progress(33);
|
||||
|
||||
// TODO: add fuzzy search and normalise strings before matching
|
||||
const superstreamEntry = searchRes.find(
|
||||
(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");
|
||||
|
|
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