mirror of
https://github.com/shafat-96/anicrush-api.git
synced 2026-04-17 15:51:44 +00:00
Update mapper.js
This commit is contained in:
53
mapper.js
53
mapper.js
@@ -268,12 +268,33 @@ function parseEpisodeList(episodeList) {
|
|||||||
return episodes.sort((a, b) => a.number - b.number);
|
return episodes.sort((a, b) => a.number - b.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to fetch ani.zip mappings
|
||||||
|
async function getAniZipMappings(anilistId) {
|
||||||
|
try {
|
||||||
|
const response = await axios({
|
||||||
|
method: 'GET',
|
||||||
|
url: `https://api.ani.zip/mappings?anilist_id=${anilistId}`,
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching ani.zip mappings:', error.message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Main mapper function
|
// Main mapper function
|
||||||
async function mapAniListToAnicrush(anilistId) {
|
async function mapAniListToAnicrush(anilistId) {
|
||||||
try {
|
try {
|
||||||
// Get AniList details
|
// Get AniList details
|
||||||
const anilistData = await getAniListDetails(anilistId);
|
const anilistData = await getAniListDetails(anilistId);
|
||||||
|
|
||||||
|
// Get ani.zip mappings for episode images
|
||||||
|
const aniZipData = await getAniZipMappings(anilistId);
|
||||||
|
|
||||||
// Try all possible titles for search
|
// Try all possible titles for search
|
||||||
const titlesToTry = [
|
const titlesToTry = [
|
||||||
anilistData.title.romaji,
|
anilistData.title.romaji,
|
||||||
@@ -301,14 +322,21 @@ async function mapAniListToAnicrush(anilistId) {
|
|||||||
const episodeList = await getEpisodeList(bestMatch.id);
|
const episodeList = await getEpisodeList(bestMatch.id);
|
||||||
const parsedEpisodes = parseEpisodeList(episodeList);
|
const parsedEpisodes = parseEpisodeList(episodeList);
|
||||||
|
|
||||||
// Create episode mapping
|
// Create episode mapping with images from ani.zip
|
||||||
const episodes = parsedEpisodes.map(ep => ({
|
const episodes = parsedEpisodes.map(ep => {
|
||||||
number: ep.number,
|
const aniZipEpisode = aniZipData?.episodes?.[ep.number] || {};
|
||||||
name: ep.name,
|
return {
|
||||||
name_english: ep.name_english,
|
number: ep.number,
|
||||||
is_filler: ep.is_filler,
|
name: ep.name,
|
||||||
id: `${bestMatch.id}?episode=${ep.number}`
|
name_english: ep.name_english,
|
||||||
}));
|
is_filler: ep.is_filler,
|
||||||
|
id: `${bestMatch.id}?episode=${ep.number}`,
|
||||||
|
image: aniZipEpisode.image || null,
|
||||||
|
overview: aniZipEpisode.overview || null,
|
||||||
|
airDate: aniZipEpisode.airDate || null,
|
||||||
|
runtime: aniZipEpisode.runtime || null
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
anilist_id: anilistId,
|
anilist_id: anilistId,
|
||||||
@@ -319,7 +347,8 @@ async function mapAniListToAnicrush(anilistId) {
|
|||||||
native: anilistData.title.native,
|
native: anilistData.title.native,
|
||||||
synonyms: anilistData.synonyms,
|
synonyms: anilistData.synonyms,
|
||||||
anicrush: bestMatch.name,
|
anicrush: bestMatch.name,
|
||||||
anicrush_english: bestMatch.name_english
|
anicrush_english: bestMatch.name_english,
|
||||||
|
additional: aniZipData?.titles || {}
|
||||||
},
|
},
|
||||||
type: bestMatch.type,
|
type: bestMatch.type,
|
||||||
total_episodes: episodes.length,
|
total_episodes: episodes.length,
|
||||||
@@ -330,7 +359,8 @@ async function mapAniListToAnicrush(anilistId) {
|
|||||||
genres: bestMatch.genres,
|
genres: bestMatch.genres,
|
||||||
country_of_origin: anilistData.countryOfOrigin,
|
country_of_origin: anilistData.countryOfOrigin,
|
||||||
year: anilistData.seasonYear,
|
year: anilistData.seasonYear,
|
||||||
description: anilistData.description
|
description: anilistData.description,
|
||||||
|
images: aniZipData?.images || []
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -341,5 +371,6 @@ async function mapAniListToAnicrush(anilistId) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mapAniListToAnicrush,
|
mapAniListToAnicrush,
|
||||||
getCommonHeaders
|
getCommonHeaders,
|
||||||
|
getAniZipMappings
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user