Update episode.js

This commit is contained in:
2025-05-08 20:43:34 +05:00
committed by GitHub
parent 33d5929f56
commit ce91c57149

View File

@@ -1,93 +1,100 @@
const axios = require('axios'); const axios = require('axios');
// Функция для запроса к Anixart API // ===== Anixart API =====
async function getEpisodeFromAnixart(releaseId, token = '') { async function getEpisodeTypes(releaseId, token = '') {
const url = `https://api.anixart.tv/episode/${releaseId}${token ? `?token=${token}` : ''}`; const url = `https://api.anixart.tv/episode/${releaseId}${token ? `?token=${token}` : ''}`;
try { try {
const response = await axios.get(url); const { data } = await axios.get(url);
const data = response.data; if (!data.types || data.types.length === 0) throw new Error("Empty types");
data.types = data.types.map(type => ({
// Изменение структуры поля `workers`
data.types = data.types.map((type) => ({
...type, ...type,
// id: 0,
workers: "источник: seele.su", workers: "источник: seele.su",
// name: "Недоступно (⁠≧⁠▽⁠≦⁠)",
// icon: null,
// view_count: null,
// pinned: false,
// episodes_count: null,
})); }));
// Если список `types` пуст, обращаемся к Seele API
if (data.code === 1 || data.types.length === 0) {
return await getEpisodeFromSeele(releaseId, token);
}
return data; return data;
} catch (error) { } catch {
console.error("Ошибка при запросе к Anixart API:", error.message); return getEpisodeTypesFromSeele(releaseId, token);
throw new Error("Ошибка при получении данных из Anixart API");
} }
} }
// Функция для запроса к Seele API async function getSources(releaseId, typeId, token = '') {
async function getEpisodeFromSeele(releaseId, token = '') { const url = `https://api.anixart.tv/episode/${releaseId}/${typeId}${token ? `?token=${token}` : ''}`;
try {
const { data } = await axios.get(url);
if (!data.sources || data.sources.length === 0) throw new Error("Empty sources");
return data;
} catch {
return getSourcesFromSeele(releaseId, typeId, token);
}
}
async function getEpisodes(releaseId, typeId, sourceId, token = '') {
const url = `https://api.anixart.tv/episode/${releaseId}/${typeId}/${sourceId}${token ? `?token=${token}` : ''}`;
try {
const { data } = await axios.get(url);
if (!data.episodes || data.episodes.length === 0) throw new Error("Empty episodes");
return data;
} catch {
return getEpisodesFromSeele(releaseId, typeId, sourceId, token);
}
}
// ===== Seele Fallback API =====
async function getEpisodeTypesFromSeele(releaseId, token = '') {
const url = `https://cloud.seele.su/episode/${releaseId}.json${token ? `?token=${token}` : ''}`; const url = `https://cloud.seele.su/episode/${releaseId}.json${token ? `?token=${token}` : ''}`;
try { try {
const response = await axios.get(url); const { data } = await axios.get(url);
const data = response.data; if (!data.types || data.types.length === 0) return getCustomNotFoundResponse();
data.types = data.types.map(type => ({
// Проверяем наличие `types`, если пусто - возвращаем кастомный ответ
if (!data.types || data.types.length === 0) {
return getCustomNotFoundResponse();
}
// Изменение структуры поля `workers`
data.types = data.types.map((type) => ({
...type, ...type,
workers: "источник: seele.su", workers: "источник: seele.su",
})); }));
return data; return data;
} catch (error) { } catch (error) {
// Если ошибка - 404, возвращаем кастомный ответ if (error.response?.status === 404) return getCustomNotFoundResponse();
if (error.response && error.response.status === 404) {
return getCustomNotFoundResponse();
}
console.error("Ошибка при запросе к Seele API:", error.message);
throw new Error("Ошибка при получении данных из Seele API"); throw new Error("Ошибка при получении данных из Seele API");
} }
} }
// Функция для создания кастомного JSON-ответа // Заглушки — если в Seele реально нет таких endpoint
async function getSourcesFromSeele(releaseId, typeId, token = '') {
return { code: 0, sources: [] };
}
async function getEpisodesFromSeele(releaseId, typeId, sourceId, token = '') {
return { code: 0, episodes: [] };
}
// ===== Кастомный ответ =====
function getCustomNotFoundResponse() { function getCustomNotFoundResponse() {
return { return {
"code": 0, code: 0,
"types": [ types: [
{ {
"@id": 1, id: 1,
"id": 1, name: "К сожалению, это аниме недоступно!",
"name": "К сожалению, это аниме недоступно!", icon: "https://cloud.seele.su/images/seele.jpg",
"icon": "https://cloud.seele.su/images/seele.jpg", workers: "Это аниме полностью удалено с сервера anixart, либо его там не было изначально.",
"workers": "Это аниме полностью удалено с сервера anixart, либо его там не было изначально.", is_sub: false,
"is_sub": false, episodes_count: 0,
"episodes_count": 0, view_count: 0,
"view_count": 0, pinned: false,
"pinned": false
}, },
{ {
"@id": 2, id: 2,
"id": 2, name: "Не забудьте подписаться на наш Telegram-канал",
"name": "Не забудьте подписаться на наш Telegram-канал 😊", icon: "https://cloud.seele.su/images/seele.jpg",
"icon": "https://cloud.seele.su/images/seele.jpg", workers: "Тгк: @seele_channel",
"workers": "Тгк: @seele_channel", is_sub: false,
"is_sub": false, episodes_count: 0,
"episodes_count": 0, view_count: 0,
"view_count": 0, pinned: false,
"pinned": false },
} ],
]
}; };
} }
module.exports = { getEpisodeFromAnixart }; module.exports = {
getEpisodeTypes,
getSources,
getEpisodes,
};