mirror of
https://github.com/shafat-96/anicrush-api.git
synced 2026-04-17 15:51:44 +00:00
Your commit message
This commit is contained in:
30
mapper.js
30
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;
|
||||
}
|
||||
}
|
||||
|
||||
3
package-lock.json
generated
3
package-lock.json
generated
@@ -15,6 +15,9 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "18.x"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
|
||||
Reference in New Issue
Block a user