Update episode.js

This commit is contained in:
2025-05-27 19:45:43 +05:00
committed by GitHub
parent 02411df666
commit d427fe47fd

View File

@@ -1,40 +1,28 @@
const axios = require('axios'); const axios = require('axios');
const fs = require('fs');
const loginList = require('./login.json');
// Получить логин по токену // Функция для запроса к Anixart API
async function getLoginFromToken(token) {
try {
const response = await axios.get(`https://api.anixart.tv/profile/preference/login/info?token=${token}`);
return response.data.login;
} catch (error) {
console.error("Ошибка при получении логина по токену:", error.message);
return null;
}
}
// Главная функция получения эпизода
async function getEpisodeFromAnixart(releaseId, token = '') { async function getEpisodeFromAnixart(releaseId, token = '') {
const login = token ? await getLoginFromToken(token) : null;
const allowedLogins = loginList.map(u => u.login);
if (!login || !allowedLogins.includes(login)) {
return getAccessDeniedResponse();
}
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 { data } = await axios.get(url); const response = await axios.get(url);
const data = response.data;
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) { if (data.code === 1 || data.types.length === 0) {
return await getEpisodeFromSeele(releaseId, token); return await getEpisodeFromSeele(releaseId, token);
} }
return data; return data;
} catch (error) { } catch (error) {
console.error("Ошибка при запросе к Anixart API:", error.message); console.error("Ошибка при запросе к Anixart API:", error.message);
@@ -42,53 +30,28 @@ async function getEpisodeFromAnixart(releaseId, token = '') {
} }
} }
function getAccessDeniedResponse() { // Функция для запроса к Seele API
return {
code: 0,
types: [
{
"@id": 1,
id: 1,
name: "Для просмотра требуется Anixart EX",
icon: "https://cloud.seele.su/images/seele.jpg",
workers: "Купить доступ: @seele_off",
is_sub: false,
episodes_count: 0,
view_count: 0,
pinned: false
},
{
"@id": 2,
id: 2,
name: "Не забудьте подписаться на наш Telegram-канал!",
icon: "https://cloud.seele.su/images/seele.jpg",
workers: "ТГК: @seele_channel",
is_sub: false,
episodes_count: 0,
view_count: 0,
pinned: false
}
]
};
}
async function getEpisodeFromSeele(releaseId, token = '') { async function getEpisodeFromSeele(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 { data } = await axios.get(url); const response = await axios.get(url);
const data = response.data;
// Проверяем наличие `types`, если пусто - возвращаем кастомный ответ
if (!data.types || data.types.length === 0) { if (!data.types || data.types.length === 0) {
return getCustomNotFoundResponse(); return getCustomNotFoundResponse();
} }
data.types = data.types.map(type => ({ // Изменение структуры поля `workers`
data.types = data.types.map((type) => ({
...type, ...type,
workers: "источник: seele.su", workers: "источник: seele.su",
})); }));
return data; return data;
} catch (error) { } catch (error) {
if (error.response?.status === 404) { // Если ошибка - 404, возвращаем кастомный ответ
if (error.response && error.response.status === 404) {
return getCustomNotFoundResponse(); return getCustomNotFoundResponse();
} }
console.error("Ошибка при запросе к Seele API:", error.message); console.error("Ошибка при запросе к Seele API:", error.message);
@@ -96,31 +59,32 @@ async function getEpisodeFromSeele(releaseId, token = '') {
} }
} }
// Функция для создания кастомного JSON-ответа
function getCustomNotFoundResponse() { function getCustomNotFoundResponse() {
return { return {
code: 0, "code": 0,
types: [ "types": [
{ {
"@id": 1, "@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, "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
} }
] ]
}; };