ffx-movie-api / app.py
ffxbot's picture
Update app.py
3abf98e verified
Raw
History Blame
1.89 kB
from fastapi import FastAPI
from duckduckgo_search import DDGS
app = FastAPI()
@app.get("/")
def home():
return {"status": "✦ 𝐅𝐅𝐗 ✦ Universal Search API is Live!"}
@app.get("/search")
def search_all(query: str):
if not query:
return {"error": "Query is required"}
results = {
"query": query,
"videos": [],
"images": [],
"files": [],
"web": []
}
try:
with DDGS() as ddgs:
# 🎬 ভিডিও
try:
for r in ddgs.videos(query, safesearch="off", max_results=3):
results["videos"].append({"title": r.get("title", ""), "link": r.get("content", "") or r.get("url", "")})
except: pass
# 🖼️ ছবি
try:
for r in ddgs.images(query, safesearch="off", max_results=3):
results["images"].append({"title": r.get("title", ""), "link": r.get("image", "") or r.get("url", "")})
except: pass
# 📂 ফাইল
try:
file_query = f"{query} ext:pdf OR ext:apk OR ext:zip OR torrent"
for r in ddgs.text(file_query, safesearch="off", max_results=3):
results["files"].append({"title": r.get("title", ""), "link": r.get("href", "")})
except: pass
# 🌐 ওয়েবসাইট
try:
web_query = f"{query} watch online OR download OR official site"
for r in ddgs.text(web_query, safesearch="off", max_results=4):
results["web"].append({"title": r.get("title", ""), "link": r.get("href", "")})
except: pass
except Exception as e:
return {"error": str(e)}
return results