Update episode.js
This commit is contained in:
@@ -1,53 +1,76 @@
|
|||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
// ===== Anixart API =====
|
// ===== Основная функция (старое имя) =====
|
||||||
|
async function getEpisodeFromAnixart(releaseId, token = '') {
|
||||||
|
try {
|
||||||
|
const data = await getEpisodeTypes(releaseId, token);
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка в getEpisodeFromAnixart:", error.message);
|
||||||
|
throw new Error("Не удалось получить данные с Anixart и Seele");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== Получение списка озвучек =====
|
||||||
async function getEpisodeTypes(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 { data } = await axios.get(url);
|
const { data } = await axios.get(url);
|
||||||
|
|
||||||
if (!data.types || data.types.length === 0) throw new Error("Empty types");
|
if (!data.types || data.types.length === 0) throw new Error("Empty types");
|
||||||
|
|
||||||
data.types = data.types.map(type => ({
|
data.types = data.types.map(type => ({
|
||||||
...type,
|
...type,
|
||||||
workers: "источник: seele.su",
|
workers: "источник: seele.su",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch {
|
} catch {
|
||||||
return getEpisodeTypesFromSeele(releaseId, token);
|
return await getEpisodeTypesFromSeele(releaseId, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== Получение источников видео (по озвучке) =====
|
||||||
async function getSources(releaseId, typeId, token = '') {
|
async function getSources(releaseId, typeId, token = '') {
|
||||||
const url = `https://api.anixart.tv/episode/${releaseId}/${typeId}${token ? `?token=${token}` : ''}`;
|
const url = `https://api.anixart.tv/episode/${releaseId}/${typeId}${token ? `?token=${token}` : ''}`;
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get(url);
|
const { data } = await axios.get(url);
|
||||||
|
|
||||||
if (!data.sources || data.sources.length === 0) throw new Error("Empty sources");
|
if (!data.sources || data.sources.length === 0) throw new Error("Empty sources");
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch {
|
} catch {
|
||||||
return getSourcesFromSeele(releaseId, typeId, token);
|
return await getSourcesFromSeele(releaseId, typeId, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== Получение эпизодов (по источнику) =====
|
||||||
async function getEpisodes(releaseId, typeId, sourceId, token = '') {
|
async function getEpisodes(releaseId, typeId, sourceId, token = '') {
|
||||||
const url = `https://api.anixart.tv/episode/${releaseId}/${typeId}/${sourceId}${token ? `?token=${token}` : ''}`;
|
const url = `https://api.anixart.tv/episode/${releaseId}/${typeId}/${sourceId}${token ? `?token=${token}` : ''}`;
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get(url);
|
const { data } = await axios.get(url);
|
||||||
|
|
||||||
if (!data.episodes || data.episodes.length === 0) throw new Error("Empty episodes");
|
if (!data.episodes || data.episodes.length === 0) throw new Error("Empty episodes");
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch {
|
} catch {
|
||||||
return getEpisodesFromSeele(releaseId, typeId, sourceId, token);
|
return await getEpisodesFromSeele(releaseId, typeId, sourceId, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== Seele Fallback API =====
|
// ===== Seele API fallback (если Anixart недоступен) =====
|
||||||
async function getEpisodeTypesFromSeele(releaseId, token = '') {
|
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 { data } = await axios.get(url);
|
const { data } = await axios.get(url);
|
||||||
|
|
||||||
if (!data.types || data.types.length === 0) return getCustomNotFoundResponse();
|
if (!data.types || data.types.length === 0) return getCustomNotFoundResponse();
|
||||||
|
|
||||||
data.types = data.types.map(type => ({
|
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) return getCustomNotFoundResponse();
|
if (error.response?.status === 404) return getCustomNotFoundResponse();
|
||||||
@@ -55,7 +78,7 @@ async function getEpisodeTypesFromSeele(releaseId, token = '') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Заглушки — если в Seele реально нет таких endpoint
|
// ===== Заглушки (если нет Seele API для sources/episodes) =====
|
||||||
async function getSourcesFromSeele(releaseId, typeId, token = '') {
|
async function getSourcesFromSeele(releaseId, typeId, token = '') {
|
||||||
return { code: 0, sources: [] };
|
return { code: 0, sources: [] };
|
||||||
}
|
}
|
||||||
@@ -64,7 +87,7 @@ async function getEpisodesFromSeele(releaseId, typeId, sourceId, token = '') {
|
|||||||
return { code: 0, episodes: [] };
|
return { code: 0, episodes: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== Кастомный ответ =====
|
// ===== Заглушка, если вообще ничего нет =====
|
||||||
function getCustomNotFoundResponse() {
|
function getCustomNotFoundResponse() {
|
||||||
return {
|
return {
|
||||||
code: 0,
|
code: 0,
|
||||||
@@ -94,7 +117,7 @@ function getCustomNotFoundResponse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getEpisodeTypes,
|
getEpisodeFromAnixart,
|
||||||
getSources,
|
getSources,
|
||||||
getEpisodes,
|
getEpisodes,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user