File size: 1,891 Bytes
b82bad9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3abf98e
b82bad9
 
 
 
 
3abf98e
b82bad9
 
 
 
 
3abf98e
b82bad9
 
 
 
 
 
3abf98e
b82bad9
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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