Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
imagens anroll
Browse files Browse the repository at this point in the history
  • Loading branch information
uesleibros committed Sep 1, 2024
1 parent fb0dc5a commit 05d50c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
19 changes: 17 additions & 2 deletions src/app/api/buscar/animes/anroll/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,36 @@ async function pegarInformacoesDetalhadasAnime(data) {
}

export async function GET(request) {
const query = request.nextUrl.searchParams.get("q");
let query = request.nextUrl.searchParams.get("q");

if (!query)
return Response.json({ error: "missing query." }, { status: 401 });

query = query.replace('×', 'x').replace(':', '').toLowerCase();
const res = await fetch(`https://api-search.anroll.net/data?q=${query}`, {
cache: "no-store"
});

let {data} = await res.json();
let responses = []

if (!data.length)
return Response.json({ error: "anime not found." }, { status: 404 });

data = data.filter((i) => i.title.replace('×', 'x').replace(':', '').toLowerCase().startsWith(query.toLowerCase()) || i.slug.includes(toSlug(query.toLowerCase())));
if (data.length > 1) {
for (let i = 0; i < data.length; i++) {
let item = data[i];
item.title = item.title.replace('×', 'x').replace(':', '').toLowerCase();
console.log(item.title)

if (item.title.startsWith(query))
responses.push(item);
if (item.title.split(' ')[0].includes(query.split(' ')[0]))
responses.push(item);
}
}

data = responses;
data.forEach((i) => i.thumbnail = `https://static.anroll.net/images/${i.type === "movie" ? "filmes" : "animes"}/capas/${i.slug}.jpg`);
for (let i = 0; i < data.length; i++) {
data[i].extra_data = await pegarInformacoesDetalhadasAnime(data[i]);
Expand Down
1 change: 0 additions & 1 deletion src/app/api/imagens/anroll/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export async function GET(request) {
status: 200,
headers: {
"Content-Type": "image/webp",
"Content-Disposition": "inline",
"Content-Length": contentLength
},
});
Expand Down
11 changes: 8 additions & 3 deletions src/app/api/streaming/anroll/[slug]/media.m3u8/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ export async function GET(request) {
if (!res.ok)
return new Response(JSON.stringify({ error: "Failed to fetch the .m3u8 file." }), { status: res.status });

const buffer = await res.arrayBuffer();
const m3u8Text = await res.text();

return new Response(buffer, {
const updatedM3U8Text = m3u8Text.replace(/(https:\/\/[^\s]+)/g, (url) => {
const encodedUrl = encodeURIComponent(url);
return `${request.headers.get("x-forwarded-proto") || "http"}://${request.headers.get("host")}/api/imagens/anroll?q=${encodedUrl}`;
});

return new Response(updatedM3U8Text, {
headers: {
"Content-Type": "application/vnd.apple.mpegurl",
"Content-Disposition": `attachment; filename="${slug}.m3u8"`,
"Content-Length": buffer.byteLength,
"Content-Length": Buffer.byteLength(updatedM3U8Text, "utf8"),
"Cache-Control": "no-store"
}
});
Expand Down
9 changes: 3 additions & 6 deletions src/components/Anime/AnrollAnimeInfos.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@ export default function AnrollAnimeInfos({anime}) {
try1 = await tentaPegarDadosAnimeAnroll(anime.synonyms[i]);
}
const try2 = await tentaPegarDadosAnimeAnroll(anime.title.english);
const try3 = await tentaPegarDadosAnimeAnroll(toSlug(anime.title.english));

if (try1) {
setAnimeAnroll(try1);
} else if (try2) {
setAnimeAnroll(try2)
} else if (try3) {
setAnimeAnroll(try3);
}
}
}
Expand Down Expand Up @@ -246,8 +243,8 @@ export default function AnrollAnimeInfos({anime}) {
</h3>
</div>
{animeAnroll?.type === "movie" && (
<div className="mt-10">
<div id="player"></div>
<div className="mt-10 !w-full !h-[510px]">
<div className="!h-full !w-full" id="player"></div>
</div>
)}
{episodios.length > 0 && (
Expand All @@ -274,7 +271,7 @@ export default function AnrollAnimeInfos({anime}) {
</button>
</div>
) : (
animeAnroll && (
(animeAnroll && animeAnroll?.type === "anime") && (
<div>
<p className="text-sm font-semibold text-zinc-500 select-none">Sem mais episódios. {anime.nextAiringEpisode && (formatAiringEpisode(anime.nextAiringEpisode))}</p>
</div>
Expand Down

0 comments on commit 05d50c5

Please sign in to comment.