Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from playwright.sync_api import sync_playwright
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
app = FastAPI(title="Neon Anime Scraper")
|
| 6 |
+
|
| 7 |
+
@app.get("/api/episode")
|
| 8 |
+
def get_episode(anime: str, episode: int, dub: str = "sub"):
|
| 9 |
+
if not anime or not episode:
|
| 10 |
+
raise HTTPException(status_code=400, detail="anime and episode required")
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
with sync_playwright() as p:
|
| 14 |
+
browser = p.chromium.launch(headless=True)
|
| 15 |
+
page = browser.new_page()
|
| 16 |
+
url = f"https://hianime.tv/{anime}-episode-{episode}"
|
| 17 |
+
page.goto(url)
|
| 18 |
+
video_element = page.query_selector("video source")
|
| 19 |
+
stream_url = video_element.get_attribute("src") if video_element else None
|
| 20 |
+
browser.close()
|
| 21 |
+
|
| 22 |
+
if not stream_url:
|
| 23 |
+
raise HTTPException(status_code=404, detail="Stream URL not found")
|
| 24 |
+
|
| 25 |
+
return {"anime": anime, "episode": episode, "dub": dub, "streamUrl": stream_url}
|
| 26 |
+
|
| 27 |
+
except Exception as e:
|
| 28 |
+
raise HTTPException(status_code=500, detail=f"Failed to scrape episode: {str(e)}")
|