Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Query
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
import requests
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
app = FastAPI(title="Catbox / Litterbox Raw File Extractor API")
|
| 7 |
+
|
| 8 |
+
# Allow cross-origin calls (optional, needed if frontend calls it)
|
| 9 |
+
app.add_middleware(
|
| 10 |
+
CORSMiddleware,
|
| 11 |
+
allow_origins=["*"],
|
| 12 |
+
allow_methods=["*"],
|
| 13 |
+
allow_headers=["*"],
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
@app.get("/api/extract")
|
| 17 |
+
def extract_raw_file(url: str = Query(..., description="Full Catbox/Litterbox URL")):
|
| 18 |
+
"""
|
| 19 |
+
Extracts a direct raw file link from a Catbox/Litterbox URL.
|
| 20 |
+
Returns JSON with `direct_link` if successful.
|
| 21 |
+
"""
|
| 22 |
+
if not url.startswith("http"):
|
| 23 |
+
raise HTTPException(status_code=400, detail="Invalid URL")
|
| 24 |
+
|
| 25 |
+
# If it already points to a raw file, return as-is
|
| 26 |
+
if re.search(r'\.(mp4|png|jpg|jpeg|gif|webm)$', url, re.IGNORECASE):
|
| 27 |
+
return {"ok": True, "direct_link": url}
|
| 28 |
+
|
| 29 |
+
# Otherwise, fetch page and try to extract the direct file
|
| 30 |
+
try:
|
| 31 |
+
resp = requests.get(url, timeout=10)
|
| 32 |
+
resp.raise_for_status()
|
| 33 |
+
html = resp.text
|
| 34 |
+
|
| 35 |
+
match = re.search(r'src="([^"]+\.(mp4|png|jpg|jpeg|gif|webm))"', html, re.IGNORECASE)
|
| 36 |
+
if match:
|
| 37 |
+
return {"ok": True, "direct_link": match.group(1)}
|
| 38 |
+
else:
|
| 39 |
+
return {"ok": False, "error": "Could not find raw file link"}
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return {"ok": False, "error": str(e)}
|