Browse Source

fuzzy matching for title

Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
pull/143/head
mrjvs 2 years ago
parent
commit
4d4626806d
  1. 4
      src/backend/providers/flixhq.ts
  2. 4
      src/backend/providers/superstream/index.ts
  3. 7
      src/utils/titleMatch.ts

4
src/backend/providers/flixhq.ts

@ -1,3 +1,4 @@ @@ -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({ @@ -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;

4
src/backend/providers/superstream/index.ts

@ -10,6 +10,7 @@ import { @@ -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({ @@ -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

@ -0,0 +1,7 @@ @@ -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…
Cancel
Save