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

Commit

Permalink
resolvido problema de acessar episódios por conta do IP no Cloudflare.
Browse files Browse the repository at this point in the history
  • Loading branch information
uesleibros committed Sep 1, 2024
1 parent 3e97326 commit fb0dc5a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 12 deletions.
27 changes: 24 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"disqus-react": "^1.1.5",
"framer-motion": "^11.3.28",
"next": "14.2.5",
"react": "^18",
"nextjs-toploader": "^3.6.15",
"react": "^18",
"react-dom": "^18",
"react-icons": "^5.3.0",
"react-slick": "^0.30.2",
Expand Down
6 changes: 4 additions & 2 deletions src/app/api/aleatorio/anime/anroll/route.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import config from "@/config";

async function pegarAnimeAleatorioInformacoes(id) {
const res = await fetch(`https://www.anroll.net/_next/data/DNs-ereP64IysZZGkZXqY/a/${id}.json?anime=${id}`, {
const res = await fetch(`https://www.anroll.net/_next/data/${config.anroll.buildId}/a/${id}.json?anime=${id}`, {
cache: "no-store"
});
const catalog = await res.json();
Expand All @@ -8,7 +10,7 @@ async function pegarAnimeAleatorioInformacoes(id) {
}

export async function GET() {
const res = await fetch("https://www.anroll.net/_next/data/DNs-ereP64IysZZGkZXqY/random.json", {
const res = await fetch(`https://www.anroll.net/_next/data/${config.anroll.buildId}/random.json`, {
cache: "no-store"
});
const catalog = await res.json();
Expand Down
27 changes: 27 additions & 0 deletions src/app/api/imagens/anroll/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export async function GET(request) {
const query = request.nextUrl.searchParams.get("q");

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

const res = await fetch(query, {
headers: {
"Origin": "https://www.anroll.net",
"Referer": "https://www.anroll.net/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
},
cache: "no-store"
});

const imageBuffer = await res.arrayBuffer();
const contentLength = imageBuffer.byteLength;

return new Response(imageBuffer, {
status: 200,
headers: {
"Content-Type": "image/webp",
"Content-Disposition": "inline",
"Content-Length": contentLength
},
});
}
15 changes: 11 additions & 4 deletions src/app/api/streaming/anroll/[slug]/[episodio]/media.m3u8/route.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import config from "@/config";

export async function GET(request) {
const { pathname } = new URL(request.url);

Expand All @@ -8,7 +10,7 @@ export async function GET(request) {
if (!slug || !episodio || pathParts[pathParts.length - 1] !== "media.m3u8")
return new Response(JSON.stringify({ error: "Invalid URL structure or missing slug/episodio." }), { status: 400 });

const res = await fetch(`https://cdn-zenitsu-2-gamabunta.b-cdn.net/cf/hls/animes/${slug}/${episodio}.mp4/media-1/stream.m3u8`, {
const res = await fetch(`https://${config.anroll.cdn}/cf/hls/animes/${slug}/${episodio}.mp4/media-1/stream.m3u8`, {
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
"Referer": "https://www.anroll.net/"
Expand All @@ -19,13 +21,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();

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(buffer, {
return new Response(updatedM3U8Text, {
headers: {
"Content-Type": "application/vnd.apple.mpegurl",
"Content-Disposition": `attachment; filename="${slug}-${episodio}.m3u8"`,
"Content-Length": buffer.byteLength,
"Content-Length": Buffer.byteLength(updatedM3U8Text, "utf8"),
"Cache-Control": "no-store"
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/app/api/streaming/anroll/[slug]/media.m3u8/route.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import config from "@/config";

export async function GET(request) {
const { pathname } = new URL(request.url);

Expand All @@ -7,7 +9,7 @@ export async function GET(request) {
if (!slug || pathParts[pathParts.length - 1] !== "media.m3u8")
return new Response(JSON.stringify({ error: "Invalid URL structure or missing slug." }), { status: 400 });

const res = await fetch(`https://cdn-zenitsu-2-gamabunta.b-cdn.net/cf/hls/movies/${slug}/movie.mp4/media-1/stream.m3u8`, {
const res = await fetch(`https://${config.anroll.cdn}/cf/hls/movies/${slug}/movie.mp4/media-1/stream.m3u8`, {
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
"Referer": "https://www.anroll.net/"
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default function RootLayout({ children }) {
return (
<html lang="pt-BR">
<body className={`dark ${font.className} bg-zinc-950`}>
<NextTopLoader showSpinner={false} color="orange" zIndex="9999" />
<NextUIProvider>
<NextTopLoader showSpinner={false} color="green" className="z-[10000]" />
<Header />
{children}
<Footer />
Expand Down
8 changes: 8 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = {
anroll: {
buildId: "nxb43Ok4qvT2cAlD0OLS1",
cdn: "cdn-zenitsu-2-gamabunta.b-cdn.net"
}
}

export default config;

0 comments on commit fb0dc5a

Please sign in to comment.