aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbun.lockbbin146958 -> 146196 bytes
-rw-r--r--package.json89
-rw-r--r--src/lib/Media/Anime/Airing/Subtitled/match.ts21
3 files changed, 54 insertions, 56 deletions
diff --git a/bun.lockb b/bun.lockb
index 0612850c..4ebec509 100755
--- a/bun.lockb
+++ b/bun.lockb
Binary files differ
diff --git a/package.json b/package.json
index 73b159a3..f5282881 100644
--- a/package.json
+++ b/package.json
@@ -1,47 +1,46 @@
{
- "name": "due.moe",
- "version": "0.0.0",
- "private": true,
- "scripts": {
- "dev": "vite dev",
- "build": "vite build",
- "preview": "vite preview",
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
- "lint": "prettier --plugin-search-dir . --check . && eslint .",
- "format": "prettier --plugin-search-dir . --write ."
- },
- "devDependencies": {
- "@sveltejs/adapter-vercel": "next",
- "@sveltejs/kit": "^1.20.4",
- "@types/fast-levenshtein": "^0.0.4",
- "@types/jsdom": "^21.1.6",
- "@types/string-similarity": "^4.0.2",
- "@typescript-eslint/eslint-plugin": "^5.45.0",
- "@typescript-eslint/parser": "^5.45.0",
- "eslint": "^8.28.0",
- "eslint-config-prettier": "^8.5.0",
- "eslint-plugin-svelte": "^2.30.0",
- "prettier": "^2.8.0",
- "prettier-plugin-svelte": "^2.10.1",
- "sass": "^1.69.7",
- "svelte": "^4.0.5",
- "svelte-check": "^3.4.3",
- "sveltekit-rate-limiter": "^0.4.2",
- "tslib": "^2.4.1",
- "typescript": "^5.0.0",
- "vite": "^4.4.2"
- },
- "type": "module",
- "dependencies": {
- "@vercel/postgres": "^0.5.1",
- "dexie": "^4.0.1-alpha.25",
- "fast-levenshtein": "^3.0.0",
- "jsdom": "^23.0.1",
- "lz-string": "^1.5.0",
- "modern-screenshot": "^4.4.33",
- "rss-parser": "^3.13.0",
- "string-similarity": "^4.0.4",
- "wanakana": "^5.3.1"
- }
+ "name": "due.moe",
+ "version": "0.0.0",
+ "private": true,
+ "scripts": {
+ "dev": "vite dev",
+ "build": "vite build",
+ "preview": "vite preview",
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
+ "lint": "prettier --plugin-search-dir . --check . && eslint .",
+ "format": "prettier --plugin-search-dir . --write ."
+ },
+ "devDependencies": {
+ "@sveltejs/adapter-vercel": "next",
+ "@sveltejs/kit": "^1.20.4",
+ "@types/fast-levenshtein": "^0.0.4",
+ "@types/jsdom": "^21.1.6",
+ "@types/string-similarity": "^4.0.2",
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
+ "@typescript-eslint/parser": "^5.45.0",
+ "eslint": "^8.28.0",
+ "eslint-config-prettier": "^8.5.0",
+ "eslint-plugin-svelte": "^2.30.0",
+ "prettier": "^2.8.0",
+ "prettier-plugin-svelte": "^2.10.1",
+ "sass": "^1.69.7",
+ "svelte": "^4.0.5",
+ "svelte-check": "^3.4.3",
+ "sveltekit-rate-limiter": "^0.4.2",
+ "tslib": "^2.4.1",
+ "typescript": "^5.0.0",
+ "vite": "^4.4.2"
+ },
+ "type": "module",
+ "dependencies": {
+ "@vercel/postgres": "^0.5.1",
+ "dexie": "^4.0.1-alpha.25",
+ "jsdom": "^23.0.1",
+ "lz-string": "^1.5.0",
+ "modern-screenshot": "^4.4.33",
+ "rss-parser": "^3.13.0",
+ "string-similarity": "^4.0.4",
+ "wanakana": "^5.3.1"
+ }
}
diff --git a/src/lib/Media/Anime/Airing/Subtitled/match.ts b/src/lib/Media/Anime/Airing/Subtitled/match.ts
index 1bf31b6f..74302353 100644
--- a/src/lib/Media/Anime/Airing/Subtitled/match.ts
+++ b/src/lib/Media/Anime/Airing/Subtitled/match.ts
@@ -2,7 +2,6 @@ import { get } from 'svelte/store';
import type { Media } from '../../../../AniList/media';
import settings from '$stores/settings';
import type { SubsPlease } from '$lib/Media/Anime/Airing/Subtitled/subsPlease';
-import levenshtein from 'fast-levenshtein';
import stringSimilarity from 'string-similarity';
export interface Time {
@@ -42,21 +41,21 @@ const normalizeTitle = (title: string | null) => {
const findClosestMatch = (times: Time[], titles: string[]) => {
let closestMatch: Time | null = null;
- let smallestDistance = Infinity;
- titles.forEach((animeTitle) => {
- const normalizedAnimeTitle = normalizeTitle(animeTitle);
+ titles.forEach((title) => {
+ const normalisedTitle = normalizeTitle(title);
- times.forEach((item) => {
- const normalizedItemTitle = normalizeTitle(item.title);
- const distance = levenshtein.get(normalizedAnimeTitle, normalizedItemTitle);
+ times.forEach((time) => {
+ const normalisedTimeTitle = normalizeTitle(time.title);
+ const distance = stringSimilarity.compareTwoStrings(normalisedTitle, normalisedTimeTitle);
if (
- distance < smallestDistance &&
- distance < Math.max(3, normalizedAnimeTitle.length * 0.4)
+ distance > 0.5 &&
+ (closestMatch === null ||
+ distance >
+ stringSimilarity.compareTwoStrings(normalisedTitle, normalizeTitle(closestMatch.title)))
) {
- smallestDistance = distance;
- closestMatch = item;
+ closestMatch = time;
}
});
});