Fix Anikoto dub episode detection

This commit is contained in:
Dymas
2026-08-30 14:32:41 +02:00
parent 3714e9b91e
commit 07f73ea340
4 changed files with 65 additions and 3 deletions
+59 -1
View File
@@ -217,6 +217,46 @@ async function AnimeInfo(id) {
}
}
async function fetchServerTypes(dataIds) {
if (!dataIds) return new Set();
try {
const serverUrl = `${baseUrl}/ajax/server/list?servers=${dataIds}`;
const serverRes = await global.axios.get(serverUrl, {
headers: {
"X-Requested-With": "XMLHttpRequest",
},
timeout: 7000,
});
const $ = cheerio.load(serverRes.data?.result || "");
const types = new Set();
$(".servers .type[data-type], [data-type]").each((i, el) => {
const type = String($(el).attr("data-type") || "")
.trim()
.toLowerCase();
if (type) types.add(type);
});
return types;
} catch (e) {
return new Set();
}
}
async function mapWithConcurrency(items, limit, mapper) {
const results = new Array(items.length);
let nextIndex = 0;
const workerCount = Math.min(Math.max(Number(limit) || 1, 1), items.length);
await Promise.all(
Array.from({ length: workerCount }, async () => {
while (nextIndex < items.length) {
const index = nextIndex;
nextIndex += 1;
results[index] = await mapper(items[index], index);
}
}),
);
return results;
}
async function fetchEpisode(dataId, page = 1) {
try {
let numericId = dataId;
@@ -247,6 +287,9 @@ async function fetchEpisode(dataId, page = 1) {
const $ = cheerio.load(data.result || "");
let episodes = [];
const hasDubFilter =
$('.filter.type [data-value="dub"], [data-value="dub"]').length > 0;
$("a[data-id][data-ids], .ep-item, li a, .ssl-item, a.item").each(
(i, el) => {
const epNum =
@@ -274,6 +317,21 @@ async function fetchEpisode(dataId, page = 1) {
},
);
const hasDubFlag = episodes.some((episode) =>
(episode.langs || []).includes("dub"),
);
if (hasDubFilter && episodes.length > 0 && !hasDubFlag) {
episodes = await mapWithConcurrency(episodes, 4, async (episode) => {
const dataIds = String(episode.id || "").split("|")[1] || "";
const serverTypes = await fetchServerTypes(dataIds);
const langs = new Set(episode.langs || []);
if (serverTypes.has("hsub")) langs.add("sub");
if (serverTypes.has("sub")) langs.add("sub");
if (serverTypes.has("dub")) langs.add("dub");
return { ...episode, langs: Array.from(langs) };
});
}
return {
episodes: episodes,
totalPages: 1,
@@ -526,7 +584,7 @@ async function fetchEpisodeSources(episodeIdStr, category = null) {
module.exports = {
name: "anikoto",
version: "5.0.2",
version: "5.0.3",
SearchAnime,
AnimeInfo,
fetchEpisodeSources,