Files
anixart-extension/api/v1/src/release.js
2025-05-12 13:59:17 +05:00

56 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const axios = require('axios');
// Получить данные из Shikimori
async function getShikimoriData(title) {
const searchUrl = `https://shikimori.one/api/animes?search=${encodeURIComponent(title)}&limit=1`;
const headers = {
'User-Agent': 'Mozilla/5.0 FakeAgent',
'Accept': 'application/json'
};
try {
const searchResponse = await axios.get(searchUrl, { headers });
const anime = searchResponse.data[0];
if (!anime) return null;
const rolesUrl = `https://shikimori.one/api/animes/${anime.id}/roles`;
const rolesResponse = await axios.get(rolesUrl, { headers });
const characters = rolesResponse.data
.filter(c => c.roles.includes('Main'))
.slice(0, 3)
.map(c =>
`<a href="https://shikimori.one/characters/${c.character.id}">${c.character.russian || c.character.name}</a>`
).join(', ');
return `<b>Оценки из Shikimori:</b> ${anime.score || 'N/A'}★<br><b>Главные персонажи:</b> ${characters}<br>`;
} catch (e) {
console.error('Shikimori API error:', e.message);
return null;
}
}
// Получить релиз с Anixart и дополнить данными из Shikimori
async function getReleaseFromAnixart(releaseId, token = '') {
const url = `https://api.anixart.tv/release/${releaseId}${token ? `?token=${token}` : ''}`;
try {
const response = await axios.get(url);
const release = response.data.release;
if (!release) return { code: 1, release: null };
const title = release.title_original || release.title_ru || '';
const shikiNote = await getShikimoriData(title);
const anixNote = release.note ? `<b>Примечание от Anixart:</b><br>${release.note}<br>` : '';
release.note = `${anixNote}${shikiNote || ''}`;
return { code: 0, release };
} catch (e) {
console.error('Anixart API error:', e.message);
return { code: 2, release: null };
}
}
module.exports = { getReleaseFromAnixart };