new format and marketplace
This commit is contained in:
179
anime/AnimeAV1.js
Normal file
179
anime/AnimeAV1.js
Normal file
@@ -0,0 +1,179 @@
|
||||
class AnimeAV1 {
|
||||
|
||||
constructor() {
|
||||
this.type = "anime-board"; // Required for scanner
|
||||
this.api = "https://animeav1.com";
|
||||
}
|
||||
|
||||
getSettings() {
|
||||
return {
|
||||
episodeServers: ["HLS", "HLS-DUB"],
|
||||
supportsDub: true,
|
||||
};
|
||||
}
|
||||
|
||||
async search(query) {
|
||||
const res = await fetch(`${this.api}/api/search`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ query: query.query }),
|
||||
});
|
||||
|
||||
if (!res.ok) return [];
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
return data.map(anime => ({
|
||||
id: anime.title.toLowerCase().replace(/\s+/g, '-'),
|
||||
title: anime.title,
|
||||
url: `${this.api}/anime/${anime.slug}`,
|
||||
subOrDub: "both",
|
||||
}));
|
||||
}
|
||||
|
||||
async getMetadata(id) {
|
||||
const html = await fetch(`${this.api}/media/${id}`).then(r => r.text());
|
||||
const parsed = this.parseSvelteData(html);
|
||||
const media = parsed.find(x => x?.data?.media)?.data.media ?? {};
|
||||
|
||||
// IMAGE
|
||||
const imageMatch = html.match(/<img[^>]*class="aspect-poster[^"]*"[^>]*src="([^"]+)"/i);
|
||||
const image = imageMatch ? imageMatch[1] : null;
|
||||
|
||||
// BLOCK INFO (STATUS, SEASON, YEAR)
|
||||
const infoBlockMatch = html.match(
|
||||
/<div class="flex flex-wrap items-center gap-2 text-sm">([\s\S]*?)<\/div>/
|
||||
);
|
||||
|
||||
let status = media.status ?? "Unknown";
|
||||
let season = media.seasons ?? null;
|
||||
let year = media.startDate ? Number(media.startDate.slice(0, 4)) : null;
|
||||
|
||||
if (infoBlockMatch) {
|
||||
const raw = infoBlockMatch[1];
|
||||
|
||||
// Extraer spans internos
|
||||
const spans = [...raw.matchAll(/<span[^>]*>([^<]+)<\/span>/g)].map(m => m[1].trim());
|
||||
|
||||
// EJEMPLO:
|
||||
// ["TV Anime", "•", "2025", "•", "Temporada Otoño", "•", "En emisión"]
|
||||
|
||||
const clean = spans.filter(x => x !== "•");
|
||||
|
||||
// YEAR
|
||||
const yearMatch = clean.find(x => /^\d{4}$/.test(x));
|
||||
if (yearMatch) year = Number(yearMatch);
|
||||
|
||||
// SEASON (el que contiene "Temporada")
|
||||
const seasonMatch = clean.find(x => x.toLowerCase().includes("temporada"));
|
||||
if (seasonMatch) season = seasonMatch;
|
||||
|
||||
// STATUS (normalmente "En emisión", "Finalizado", etc)
|
||||
const statusMatch = clean.find(x =>
|
||||
/emisión|finalizado|completado|pausa|cancelado/i.test(x)
|
||||
);
|
||||
if (statusMatch) status = statusMatch;
|
||||
}
|
||||
|
||||
return {
|
||||
title: media.title ?? "Unknown",
|
||||
summary: media.synopsis ?? "No summary available",
|
||||
episodes: media.episodesCount ?? 0,
|
||||
characters: [],
|
||||
season,
|
||||
status,
|
||||
studio: "Unknown",
|
||||
score: media.score ?? 0,
|
||||
year,
|
||||
genres: media.genres?.map(g => g.name) ?? [],
|
||||
image
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async findEpisodes(id) {
|
||||
const html = await fetch(`${this.api}/media/${id}`).then(r => r.text());
|
||||
const parsed = this.parseSvelteData(html);
|
||||
|
||||
const media = parsed.find(x => x?.data?.media)?.data?.media;
|
||||
if (!media?.episodes) throw new Error("No se encontró media.episodes");
|
||||
|
||||
return media.episodes.map((ep, i) => ({
|
||||
id: `${media.slug}$${ep.number ?? i + 1}`,
|
||||
number: ep.number ?? i + 1,
|
||||
title: ep.title ?? `Episode ${ep.number ?? i + 1}`,
|
||||
url: `${this.api}/media/${media.slug}/${ep.number ?? i + 1}`,
|
||||
}));
|
||||
}
|
||||
|
||||
async findEpisodeServer(episodeOrId, _server) {
|
||||
const ep = typeof episodeOrId === "string"
|
||||
? (() => { try { return JSON.parse(episodeOrId); } catch { return { id: episodeOrId }; } })()
|
||||
: episodeOrId;
|
||||
|
||||
const pageUrl = ep.url ?? (
|
||||
typeof ep.id === "string" && ep.id.includes("$")
|
||||
? `${this.api}/media/${ep.id.split("$")[0]}/${ep.number ?? ep.id.split("$")[1]}`
|
||||
: undefined
|
||||
);
|
||||
|
||||
if (!pageUrl) throw new Error("No se pudo determinar la URL del episodio.");
|
||||
|
||||
const html = await fetch(pageUrl, {
|
||||
headers: { Cookie: "__ddg1_=;__ddg2_=;" },
|
||||
}).then(r => r.text());
|
||||
|
||||
const parsedData = this.parseSvelteData(html);
|
||||
const entry = parsedData.find(x => x?.data?.embeds) || parsedData[3];
|
||||
const embeds = entry?.data?.embeds;
|
||||
if (!embeds) throw new Error("No se encontraron 'embeds' en los datos del episodio.");
|
||||
|
||||
const selectedEmbeds =
|
||||
_server === "HLS"
|
||||
? embeds.SUB ?? []
|
||||
: _server === "HLS-DUB"
|
||||
? embeds.DUB ?? []
|
||||
: (() => { throw new Error(`Servidor desconocido: ${_server}`); })();
|
||||
|
||||
if (!selectedEmbeds.length)
|
||||
throw new Error(`No hay mirrors disponibles para ${_server === "HLS" ? "SUB" : "DUB"}.`);
|
||||
|
||||
const match = selectedEmbeds.find(m =>
|
||||
(m.url || "").includes("zilla-networks.com/play/")
|
||||
);
|
||||
|
||||
if (!match)
|
||||
throw new Error(`No se encontró ningún embed de ZillaNetworks en ${_server}.`);
|
||||
|
||||
return {
|
||||
server: _server,
|
||||
headers: { Referer: 'null' },
|
||||
videoSources: [
|
||||
{
|
||||
url: match.url.replace("/play/", "/m3u8/"),
|
||||
type: "m3u8",
|
||||
quality: "auto",
|
||||
subtitles: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
parseSvelteData(html) {
|
||||
const scriptMatch = html.match(/<script[^>]*>\s*({[^<]*__sveltekit_[\s\S]*?)<\/script>/i);
|
||||
if (!scriptMatch) throw new Error("No se encontró bloque SvelteKit en el HTML.");
|
||||
|
||||
const dataMatch = scriptMatch[1].match(/data:\s*(\[[\s\S]*?\])\s*,\s*form:/);
|
||||
if (!dataMatch) throw new Error("No se encontró el bloque 'data' en el script SvelteKit.");
|
||||
|
||||
const jsArray = dataMatch[1];
|
||||
try {
|
||||
return new Function(`"use strict"; return (${jsArray});`)();
|
||||
} catch {
|
||||
const cleaned = jsArray.replace(/\bvoid 0\b/g, "null").replace(/undefined/g, "null");
|
||||
return new Function(`"use strict"; return (${cleaned});`)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AnimeAV1;
|
||||
235
anime/HiAnime.js
Normal file
235
anime/HiAnime.js
Normal file
@@ -0,0 +1,235 @@
|
||||
class HiAnime {
|
||||
constructor() {
|
||||
this.type = "anime-board";
|
||||
this.baseUrl = "https://hianime.to";
|
||||
}
|
||||
|
||||
getSettings() {
|
||||
return {
|
||||
episodeServers: ["HD-1", "HD-2", "HD-3", "HD-4"],
|
||||
supportsDub: true
|
||||
};
|
||||
}
|
||||
|
||||
async search(query) {
|
||||
const normalize = (str) => this.safeString(str).toLowerCase().replace(/[^a-z0-9]+/g, "");
|
||||
|
||||
const start = query.media.startDate;
|
||||
const fetchMatches = async (url) => {
|
||||
const html = await fetch(url).then(res => res.text());
|
||||
|
||||
const regex = /<a href="\/watch\/([^"]+)"[^>]+title="([^"]+)"[^>]+data-id="(\d+)"/g;
|
||||
|
||||
return [...html.matchAll(regex)].map(m => {
|
||||
const id = m[3];
|
||||
const pageUrl = m[1];
|
||||
const title = m[2];
|
||||
|
||||
const jnameRegex = new RegExp(
|
||||
`<h3 class="film-name">[\\s\\S]*?<a[^>]+href="\\/${pageUrl}[^"]*"[^>]+data-jname="([^"]+)"`,
|
||||
"i"
|
||||
);
|
||||
const jnameMatch = html.match(jnameRegex);
|
||||
const jname = jnameMatch ? jnameMatch[1] : null;
|
||||
|
||||
const imageRegex = new RegExp(
|
||||
`<a href="/watch/${pageUrl.replace(/\//g, "\\/")}"[\\s\\S]*?<img[^>]+data-src="([^"]+)"`,
|
||||
"i"
|
||||
);
|
||||
const imageMatch = html.match(imageRegex);
|
||||
const image = imageMatch ? imageMatch[1] : null;
|
||||
|
||||
return {
|
||||
id,
|
||||
pageUrl,
|
||||
title,
|
||||
image,
|
||||
normTitleJP: normalize(this.normalizeSeasonParts(jname)),
|
||||
normTitle: normalize(this.normalizeSeasonParts(title)),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
let url = `${this.baseUrl}/search?keyword=${encodeURIComponent(query.query)}&sy=${start.year}&sm=${start.month}&sort=default`;
|
||||
let matches = await fetchMatches(url);
|
||||
|
||||
if (matches.length === 0) return [];
|
||||
|
||||
return matches.map(m => ({
|
||||
id: `${m.id}/${query.dub ? "dub" : "sub"}`,
|
||||
title: m.title,
|
||||
image: m.image,
|
||||
url: `${this.baseUrl}/${m.pageUrl}`,
|
||||
subOrDub: query.dub ? "dub" : "sub"
|
||||
}));
|
||||
}
|
||||
|
||||
async findEpisodes(animeId) {
|
||||
const [id, subOrDub] = animeId.split("/");
|
||||
const res = await fetch(`${this.baseUrl}/ajax/v2/episode/list/${id}`, {
|
||||
headers: { "X-Requested-With": "XMLHttpRequest" }
|
||||
});
|
||||
const json = await res.json();
|
||||
const html = json.html;
|
||||
console.log(html)
|
||||
|
||||
|
||||
const episodes = [];
|
||||
const regex = /<a[^>]*class="[^"]*\bep-item\b[^"]*"[^>]*data-number="(\d+)"[^>]*data-id="(\d+)"[^>]*href="([^"]+)"[\s\S]*?<div class="ep-name[^"]*"[^>]*title="([^"]+)"/g;
|
||||
|
||||
let match;
|
||||
while ((match = regex.exec(html)) !== null) {
|
||||
episodes.push({
|
||||
id: `${match[2]}/${subOrDub}`,
|
||||
number: parseInt(match[1], 10),
|
||||
url: this.baseUrl + match[3],
|
||||
title: match[4],
|
||||
});
|
||||
}
|
||||
|
||||
return episodes;
|
||||
}
|
||||
|
||||
async findEpisodeServer(episode, _server) {
|
||||
const [id, subOrDub] = episode.id.split("/");
|
||||
let serverName = _server !== "default" ? _server : "HD-1";
|
||||
|
||||
if (_server === "HD-1" || _server === "HD-2" || _server === "HD-3") {
|
||||
const serverJson = await fetch(`${this.baseUrl}/ajax/v2/episode/servers?episodeId=${id}`, {
|
||||
headers: { "X-Requested-With": "XMLHttpRequest" }
|
||||
}).then(res => res.json());
|
||||
|
||||
const serverHtml = serverJson.html;
|
||||
const regex = new RegExp(
|
||||
`<div[^>]*class="item server-item"[^>]*data-type="${subOrDub}"[^>]*data-id="(\\d+)"[^>]*>\\s*<a[^>]*>\\s*${serverName}\\s*</a>`,
|
||||
"i"
|
||||
);
|
||||
|
||||
const match = regex.exec(serverHtml);
|
||||
if (!match) throw new Error(`Server "${serverName}" (${subOrDub}) not found`);
|
||||
|
||||
const serverId = match[1];
|
||||
|
||||
const sourcesJson = await fetch(`${this.baseUrl}/ajax/v2/episode/sources?id=${serverId}`, {
|
||||
headers: { "X-Requested-With": "XMLHttpRequest" }
|
||||
}).then(res => res.json());
|
||||
|
||||
let decryptData = null;
|
||||
let requiredHeaders = {};
|
||||
|
||||
try {
|
||||
// Pass true to get headers back
|
||||
decryptData = await this.extractMegaCloud(sourcesJson.link, true);
|
||||
if (decryptData && decryptData.headersProvided) {
|
||||
requiredHeaders = decryptData.headersProvided;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("Primary decrypter failed:", err);
|
||||
}
|
||||
|
||||
if (!decryptData) {
|
||||
console.warn("Primary decrypter failed — trying ShadeOfChaos fallback...");
|
||||
const fallbackRes = await fetch(
|
||||
`https://ac-api.ofchaos.com/api/anime/embed/convert/v2?embedUrl=${encodeURIComponent(sourcesJson.link)}`
|
||||
);
|
||||
decryptData = await fallbackRes.json();
|
||||
|
||||
// CRITICAL: Fallback headers must mimic the browser behavior expected by the provider
|
||||
// These MUST be used by a server-side proxy; the browser player cannot set them.
|
||||
requiredHeaders = {
|
||||
"Referer": "https://megacloud.club/",
|
||||
"Origin": "https://megacloud.club",
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
};
|
||||
}
|
||||
|
||||
const streamSource =
|
||||
decryptData.sources.find((s) => s.type === "hls") ||
|
||||
decryptData.sources.find((s) => s.type === "mp4");
|
||||
|
||||
if (!streamSource?.file) throw new Error("No valid stream file found");
|
||||
|
||||
const subtitles = (decryptData.tracks || [])
|
||||
.filter((t) => t.kind === "captions")
|
||||
.map((track, index) => ({
|
||||
id: `sub-${index}`,
|
||||
language: track.label || "Unknown",
|
||||
url: track.file,
|
||||
isDefault: !!track.default,
|
||||
}));
|
||||
|
||||
return {
|
||||
server: serverName,
|
||||
headers: requiredHeaders,
|
||||
videoSources: [{
|
||||
url: streamSource.file,
|
||||
type: streamSource.type === "hls" ? "m3u8" : "mp4",
|
||||
quality: "auto",
|
||||
subtitles
|
||||
}]
|
||||
};
|
||||
}
|
||||
else if (_server === "HD-4") {
|
||||
// Implementation for HD-4 if needed
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
safeString(str) {
|
||||
return (typeof str === "string" ? str : "");
|
||||
}
|
||||
|
||||
normalizeSeasonParts(title) {
|
||||
const s = this.safeString(title);
|
||||
return s.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "")
|
||||
.replace(/\d+(st|nd|rd|th)/g, (m) => m.replace(/st|nd|rd|th/, ""))
|
||||
.replace(/season|cour|part/g, "");
|
||||
}
|
||||
|
||||
async extractMegaCloud(embedUrl, returnHeaders = false) {
|
||||
const url = new URL(embedUrl);
|
||||
const baseDomain = `${url.protocol}//${url.host}/`;
|
||||
|
||||
const headers = {
|
||||
"Accept": "*/*",
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"Referer": baseDomain,
|
||||
"Origin": `${url.protocol}//${url.host}`,
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
|
||||
};
|
||||
|
||||
const html = await fetch(embedUrl, { headers }).then((r) => r.text());
|
||||
const fileIdMatch = html.match(/<title>\s*File\s+#([a-zA-Z0-9]+)\s*-/i);
|
||||
if (!fileIdMatch) throw new Error("file_id not found in embed page");
|
||||
const fileId = fileIdMatch[1];
|
||||
|
||||
let nonce = null;
|
||||
const match48 = html.match(/\b[a-zA-Z0-9]{48}\b/);
|
||||
if (match48) nonce = match48[0];
|
||||
else {
|
||||
const match3x16 = [...html.matchAll(/["']([A-Za-z0-9]{16})["']/g)];
|
||||
if (match3x16.length >= 3) {
|
||||
nonce = match3x16[0][1] + match3x16[1][1] + match3x16[2][1];
|
||||
}
|
||||
}
|
||||
if (!nonce) throw new Error("nonce not found");
|
||||
|
||||
const sourcesJson = await fetch(
|
||||
`${baseDomain}embed-2/v3/e-1/getSources?id=${fileId}&_k=${nonce}`,
|
||||
{ headers }
|
||||
).then((r) => r.json());
|
||||
|
||||
return {
|
||||
sources: sourcesJson.sources,
|
||||
tracks: sourcesJson.tracks || [],
|
||||
intro: sourcesJson.intro || null,
|
||||
outro: sourcesJson.outro || null,
|
||||
server: sourcesJson.server || null,
|
||||
headersProvided: returnHeaders ? headers : undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HiAnime;
|
||||
Reference in New Issue
Block a user