QJMKWB1 / app.py
QJMKWB's picture
Rename main.py to app.py
970faba verified
from fastapi import FastAPI, Query
from fastapi.middleware.cors import CORSMiddleware
import scraper
import uvicorn
app = FastAPI(title="Movie API Backend")
# Enable CORS for the frontend
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def root():
return {"status": "online", "message": "Movie API is running"}
@app.get("/search")
async def search(q: str = Query(..., description="Search query")):
results = scraper.search_movies(q)
return results
@app.get("/details")
async def details(slug: str, type: str = "movie"):
return scraper.get_details(slug, type)
@app.get("/stream")
async def stream(
slug: str,
type: str = "movie",
s: int = None,
e: int = None,
lng: str = None,
source: int = 0
):
result = scraper.get_stream_url(slug, type, season=s, episode=e, lang=lng, source_idx=source)
if result["stream"]:
return {
"success": True,
"stream": result["stream"],
"vtt": result["vtt"]
}
return {
"success": False,
"error": "Stream not found by scraper"
}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7860)