From 227c231e4b224baf6a5587bf5438a95bcc7e8b0f Mon Sep 17 00:00:00 2001 From: shafat420 Date: Tue, 6 May 2025 22:11:03 +0600 Subject: [PATCH] Your commit message --- mapper.js | 30 +++++++++++++++++++++++------- package-lock.json | 3 +++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/mapper.js b/mapper.js index a65a7e8..4c62e2e 100644 --- a/mapper.js +++ b/mapper.js @@ -211,6 +211,19 @@ function findBestMatch(anilistData, anicrushResults) { let bestMatch = null; let highestSimilarity = 0; + // Map AniList format to Anicrush type + const formatTypeMap = { + 'TV': 'TV', + 'TV_SHORT': 'TV', + 'MOVIE': 'MOVIE', + 'SPECIAL': 'SPECIAL', + 'OVA': 'OVA', + 'ONA': 'ONA', + 'MUSIC': 'MUSIC' + }; + + const expectedType = formatTypeMap[anilistData.format] || null; + // Check each result from anicrush for (const result of anicrushResults.result.movies) { const resultTitles = [ @@ -227,16 +240,19 @@ function findBestMatch(anilistData, anicrushResults) { ); // Add bonus for year match + let currentSimilarity = similarity; if (anilistData.seasonYear && result.aired_from) { const yearMatch = result.aired_from.includes(anilistData.seasonYear.toString()); - const currentSimilarity = similarity + (yearMatch ? 15 : 0); + if (yearMatch) currentSimilarity += 15; + } + + // Add bonus for type match + if (expectedType && result.type && expectedType === result.type) { + currentSimilarity += 20; // Higher bonus for type match + } - if (currentSimilarity > highestSimilarity) { - highestSimilarity = currentSimilarity; - bestMatch = result; - } - } else if (similarity > highestSimilarity) { - highestSimilarity = similarity; + if (currentSimilarity > highestSimilarity) { + highestSimilarity = currentSimilarity; bestMatch = result; } } diff --git a/package-lock.json b/package-lock.json index 69579f5..9c0f25c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,9 @@ }, "devDependencies": { "nodemon": "^3.0.2" + }, + "engines": { + "node": "18.x" } }, "node_modules/accepts": {