Skip to content

Commit 59992fc

Browse files
committed
I hope this is the last commit
1 parent 2183158 commit 59992fc

8 files changed

Lines changed: 189 additions & 188 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
lint-and-build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
cache: npm
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Lint
27+
run: npm run lint
28+
29+
- name: Build
30+
run: npm run build

‎src/app/api/extract-sora/route.ts‎

Lines changed: 119 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,156 @@
1-
import { NextResponse } from 'next/server';
1+
import { NextResponse } from "next/server";
2+
3+
const SORA_UA =
4+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36";
5+
6+
function extractFromHtml(html: string): { mp4Url: string; prompt: string } {
7+
let mp4Url = "";
8+
let prompt = "";
9+
10+
const metaVideoMatch = html.match(/<meta property="og:video" content="([^"]+)"/i);
11+
if (metaVideoMatch?.[1]) {
12+
mp4Url = metaVideoMatch[1];
13+
} else {
14+
const videoMatch = html.match(/"([^"]*\.mp4[^"]*)"/i);
15+
if (videoMatch?.[1]) mp4Url = videoMatch[1];
16+
}
17+
18+
mp4Url = mp4Url.replace(/\\u0026/g, "&");
19+
20+
const metaDescMatch = html.match(/<meta property="og:description" content="([^"]+)"/i);
21+
if (metaDescMatch?.[1]) {
22+
prompt = metaDescMatch[1].trim();
23+
} else {
24+
const titleMatch = html.match(/<title>([^<]+)<\/title>/i);
25+
if (titleMatch?.[1]) prompt = titleMatch[1].replace(/Sora/gi, "").trim();
26+
}
27+
28+
prompt = prompt.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
29+
30+
return { mp4Url, prompt };
31+
}
32+
33+
async function safeFetch(url: string): Promise<Response | null> {
34+
try {
35+
return await fetch(url, { headers: { "User-Agent": SORA_UA } });
36+
} catch {
37+
return null;
38+
}
39+
}
240

341
export async function POST(request: Request) {
442
try {
5-
const body = await request.json();
6-
let url = body.url;
43+
const body = (await request.json()) as { url?: string };
44+
const url = body.url?.trim() ?? "";
745

846
if (!url) {
9-
return NextResponse.json(
10-
{ error: 'No URL provided.' },
11-
{ status: 400 }
12-
);
47+
return NextResponse.json({ error: "No URL provided." }, { status: 400 });
1348
}
1449

15-
if (!url.startsWith('https://sora.chatgpt.com/')) {
50+
if (!url.startsWith("https://sora.chatgpt.com/")) {
1651
return NextResponse.json(
17-
{ error: 'RemoveBanana requires a Sora share URL starting with https://sora.chatgpt.com/' },
52+
{ error: "RemoveBanana requires a Sora URL starting with https://sora.chatgpt.com/." },
1853
{ status: 400 }
1954
);
2055
}
2156

22-
// Fetch the raw HTML of the Sora page
23-
const response = await fetch(url, {
24-
headers: {
25-
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
26-
}
27-
});
57+
let mp4Url = "";
58+
let prompt = "";
2859

29-
if (!response.ok) {
30-
throw new Error(`HTTP error! status: ${response.status}`);
31-
}
60+
const genMatch = url.match(/\/g\/(gen_[a-zA-Z0-9]+)/);
61+
if (genMatch) {
62+
const genId = genMatch[1];
63+
const apiRes = await safeFetch(`https://sora.chatgpt.com/backend-api/video/generations/${genId}`);
64+
65+
if (apiRes?.ok) {
66+
try {
67+
const data = (await apiRes.json()) as Record<string, unknown>;
68+
mp4Url = typeof data.video_url === "string" ? data.video_url : typeof data.url === "string" ? data.url : "";
69+
prompt =
70+
typeof data.prompt === "string"
71+
? data.prompt
72+
: typeof data.caption === "string"
73+
? data.caption
74+
: "";
75+
} catch {
76+
// Ignore non-JSON responses and fall back to HTML scraping.
77+
}
78+
}
3279

33-
const html = await response.text();
80+
if (!mp4Url) {
81+
const htmlRes = await safeFetch(url);
82+
if (!htmlRes) {
83+
return NextResponse.json(
84+
{ error: "Could not reach the Sora link. Verify the URL and try again." },
85+
{ status: 400 }
86+
);
87+
}
3488

35-
// The Sora video URL is typically embedded in the meta tags or script tags payload
36-
let mp4Url = '';
37-
let prompt = '';
89+
if (!htmlRes.ok) {
90+
if (htmlRes.status === 401 || htmlRes.status === 403) {
91+
return NextResponse.json(
92+
{
93+
error:
94+
"This /g/ link is private and requires login. Use Sora Share to create a public /p/ link.",
95+
},
96+
{ status: 400 }
97+
);
98+
}
3899

39-
// 1. Try to extract MP4 URL
40-
// Look for cdns that OpenAI uses for video or regular mp4 og:video tags
41-
const videoUrlRegex = /"([^"]*\.mp4[^"]*)"/i;
42-
const metaVideoRegex = /<meta property="og:video" content="([^"]+)"/i;
100+
return NextResponse.json(
101+
{ error: `Sora returned HTTP ${htmlRes.status}. Try using a public /p/ share link.` },
102+
{ status: 400 }
103+
);
104+
}
43105

44-
// We try looking for og:video first, as it's the standard way
45-
const metaVideoMatch = html.match(metaVideoRegex);
46-
if (metaVideoMatch && metaVideoMatch[1]) {
47-
mp4Url = metaVideoMatch[1];
106+
const html = await htmlRes.text();
107+
({ mp4Url, prompt } = extractFromHtml(html));
108+
}
48109
} else {
49-
// Fallback to searching for an mp4 url within the HTML
50-
const videoMatch = html.match(videoUrlRegex);
51-
if (videoMatch && videoMatch[1]) {
52-
mp4Url = videoMatch[1];
110+
const htmlRes = await safeFetch(url);
111+
if (!htmlRes) {
112+
return NextResponse.json(
113+
{ error: "Could not reach the Sora link. Verify the URL and try again." },
114+
{ status: 400 }
115+
);
53116
}
54-
}
55117

56-
// Unescape the URL if it's JSON encoded
57-
mp4Url = mp4Url.replace(/\\u0026/g, '&');
118+
if (!htmlRes.ok) {
119+
if (htmlRes.status === 401 || htmlRes.status === 403) {
120+
return NextResponse.json(
121+
{ error: "This link is private. Use Sora Share to generate a public /p/ link." },
122+
{ status: 400 }
123+
);
124+
}
58125

59-
// 2. Try to extract the prompt
60-
// Look for og:description or title
61-
const metaDescRegex = /<meta property="og:description" content="([^"]+)"/i;
62-
const metaDescMatch = html.match(metaDescRegex);
63-
if (metaDescMatch && metaDescMatch[1]) {
64-
prompt = metaDescMatch[1].trim();
65-
} else {
66-
const titleRegex = /<title>([^<]+)<\/title>/i;
67-
const titleMatch = html.match(titleRegex);
68-
if (titleMatch && titleMatch[1]) {
69-
prompt = titleMatch[1].replace('Sora', '').trim();
126+
return NextResponse.json(
127+
{ error: `Sora returned HTTP ${htmlRes.status}. Make sure the link is public.` },
128+
{ status: 400 }
129+
);
70130
}
71-
}
72131

73-
prompt = prompt.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
132+
const html = await htmlRes.text();
133+
({ mp4Url, prompt } = extractFromHtml(html));
134+
}
74135

75136
if (!mp4Url) {
76137
return NextResponse.json(
77-
{ error: 'RemoveBanana could not extract a video from that link. Make sure it is a valid public Sora share link.' },
138+
{
139+
error:
140+
"Could not find a video in this link. For /g/ URLs, the generation may be private. Use a public /p/ share link.",
141+
},
78142
{ status: 400 }
79143
);
80144
}
81145

82146
return NextResponse.json({
83-
prompt: prompt || 'Prompt not found.',
84-
mp4Url: mp4Url
147+
prompt: prompt || "Prompt not available.",
148+
mp4Url,
85149
});
86-
87150
} catch (error) {
88-
console.error('RemoveBanana Sora extraction error:', error);
151+
console.error("RemoveBanana Sora extraction error:", error);
89152
return NextResponse.json(
90-
{ error: 'RemoveBanana hit an error while fetching the Sora video.' },
153+
{ error: "An unexpected error occurred. Please try again with a valid public Sora link." },
91154
{ status: 500 }
92155
);
93156
}

‎src/app/api/remove-gemini/route.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { removeWatermarkFromBuffer } from 'removebanana';
2-
import { NextResponse } from 'next/server';
3-
4-
1+
import { removeWatermarkFromBuffer } from "removebanana";
2+
import { NextResponse } from "next/server";
53

64
export async function POST(request: Request) {
75
try {
86
const formData = await request.formData();
9-
const image = formData.get('image') as File | null;
7+
const image = formData.get("image") as File | null;
108

119
if (!image) {
1210
return NextResponse.json(
@@ -17,7 +15,7 @@ export async function POST(request: Request) {
1715

1816
const buffer = Buffer.from(await image.arrayBuffer());
1917

20-
console.log('RemoveBanana: processing Gemini image...');
18+
console.log("RemoveBanana: processing Gemini image...");
2119

2220
// Remove the watermark using the canvas library under the hood
2321
const result = await removeWatermarkFromBuffer(buffer, {
@@ -32,15 +30,19 @@ export async function POST(request: Request) {
3230
// Return the clean image as a PNG response (BodyInit needs Uint8Array)
3331
return new NextResponse(new Uint8Array(result.buffer), {
3432
headers: {
35-
'Content-Type': 'image/png',
36-
'Content-Disposition': 'attachment; filename="removebanana-clean-image.png"',
33+
"Content-Type": "image/png",
34+
"Content-Disposition": "attachment; filename=\"removebanana-clean-image.png\"",
3735
},
3836
});
3937

40-
} catch (error: any) {
41-
console.error('RemoveBanana Gemini processing error:', error);
38+
} catch (error: unknown) {
39+
console.error("RemoveBanana Gemini processing error:", error);
40+
const message = error instanceof Error
41+
? error.message
42+
: "RemoveBanana could not process the image. Make sure it is a valid Gemini, Imagen, or Nano Banana image.";
43+
4244
return NextResponse.json(
43-
{ error: error.message || 'RemoveBanana could not process the image. Make sure it is a valid Gemini, Imagen, or Nano Banana image.' },
45+
{ error: message },
4446
{ status: 500 }
4547
);
4648
}

‎src/app/page.tsx‎

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ export default function Home() {
2828
<span className="bg-gradient-to-r from-blue-400 via-purple-400 to-fuchsia-400 bg-clip-text text-transparent">
2929
Remove
3030
</span>
31-
{/* <Image
32-
src="/Google.png"
33-
alt="Google"
34-
width={430}
35-
height={96}
36-
className="h-[0.9em] w-auto shrink-0 object-contain"
37-
priority
38-
/> */}
3931
<Image
4032
src="/Gemini.gif"
4133
alt="Gemini"
@@ -47,17 +39,6 @@ export default function Home() {
4739
<span className="bg-gradient-to-r from-blue-400 via-purple-400 to-fuchsia-400 bg-clip-text text-transparent">
4840
Watermarks
4941
</span>
50-
<span className="inline-flex items-center justify-center">
51-
{/* <Image
52-
src="/Banana.webp"
53-
alt="RemoveBanana logo"
54-
width={56}
55-
height={56}
56-
className="h-[0.95em] w-[0.95em] rounded-xl object-cover"
57-
priority
58-
/> */}
59-
</span>
60-
6142
</motion.h1>
6243

6344
<motion.p
@@ -66,7 +47,9 @@ export default function Home() {
6647
transition={{ duration: 0.5, delay: 0.2 }}
6748
className="text-lg md:text-xl text-gray-400 mb-12 max-w-2xl mx-auto leading-relaxed"
6849
>
69-
Remove invisible AI watermarks from Google Gemini-generated images using reverse alpha blending mathematics. A 100% fast and secure, lossless solution completely in your browser. </motion.p>
50+
Remove invisible AI watermarks from Google Gemini-generated images using reverse alpha blending mathematics.
51+
A fast, secure, and lossless workflow that runs directly in your browser.
52+
</motion.p>
7053
</div>
7154
<div className="flex justify-center">
7255
<motion.div
@@ -91,48 +74,6 @@ Remove invisible AI watermarks from Google Gemini-generated images using reverse
9174
</div>
9275
</section>
9376

94-
{/* Features Grid */}
95-
{/* <section id="how-it-works" className="py-24 border-t border-white/5 bg-black/40 relative">
96-
<div className="max-w-7xl mx-auto px-6">
97-
<div className="text-center mb-16">
98-
<h2 className="text-3xl md:text-5xl font-bold mb-4 tracking-tight">Why Choose Us?</h2>
99-
<p className="text-gray-400">Built as RemoveBanana by aashuu for fast, direct watermark workflows.</p>
100-
</div>
101-
102-
<div className="grid grid-cols-1 md:grid-cols-3 gap-8">
103-
<div className="glass p-8 rounded-3xl group hover:border-blue-500/30 transition-colors">
104-
<div className="w-14 h-14 rounded-2xl bg-blue-500/10 flex items-center justify-center mb-6 group-hover:scale-110 transition-transform">
105-
<Zap className="w-7 h-7 text-blue-400" />
106-
</div>
107-
<h3 className="text-xl font-bold mb-3">Mathematical Precision</h3>
108-
<p className="text-gray-400 text-sm leading-relaxed">
109-
RemoveBanana uses the exact inverse of Google&#39;s alpha blending formula to reconstruct the original pixels with precision.
110-
</p>
111-
</div>
112-
113-
<div className="glass p-8 rounded-3xl group hover:border-green-500/30 transition-colors">
114-
<div className="w-14 h-14 rounded-2xl bg-green-500/10 flex items-center justify-center mb-6 group-hover:scale-110 transition-transform">
115-
<ShieldCheck className="w-7 h-7 text-green-400" />
116-
</div>
117-
<h3 className="text-xl font-bold mb-3">100% Secure & Private</h3>
118-
<p className="text-gray-400 text-sm leading-relaxed">
119-
Process your Gemini images fast with a clean product interface, direct file flow, and a focused experience for this tool.
120-
</p>
121-
</div>
122-
123-
<div className="glass p-8 rounded-3xl group hover:border-fuchsia-500/30 transition-colors">
124-
<div className="w-14 h-14 rounded-2xl bg-fuchsia-500/10 flex items-center justify-center mb-6 group-hover:scale-110 transition-transform">
125-
<Video className="w-7 h-7 text-fuchsia-400" />
126-
</div>
127-
<h3 className="text-xl font-bold mb-3">Sora Raw Extraction</h3>
128-
<p className="text-gray-400 text-sm leading-relaxed">
129-
The second workspace is designed for Sora share-link extraction and download flows inside the same RemoveBanana product.
130-
</p>
131-
</div>
132-
</div>
133-
</div>
134-
</section> */}
135-
13677
{/* Footer */}
13778
<footer className="border-t border-white/5 py-12 text-center text-sm text-gray-500">
13879
<p>aashuu ✦</p>

0 commit comments

Comments
 (0)