Update main.py
Browse files
main.py
CHANGED
@@ -12,20 +12,19 @@ CREATOR = "Eyepatch"
|
|
12 |
API_VERSION = "1.0"
|
13 |
|
14 |
# Utility function to format API responses
|
15 |
-
def format_response(
|
16 |
return {
|
17 |
"creator": CREATOR,
|
18 |
"api_version": API_VERSION,
|
19 |
**kwargs,
|
20 |
-
data,
|
21 |
}
|
22 |
|
23 |
@app.get("/")
|
24 |
def root(request: Request):
|
25 |
-
return format_response(
|
26 |
|
27 |
@app.get("/search")
|
28 |
-
async def search(query: str, page: int):
|
29 |
payload = {
|
30 |
"search_text": query,
|
31 |
"tags": [],
|
@@ -40,10 +39,8 @@ async def search(query: str, page: int):
|
|
40 |
response_data = response.json()
|
41 |
|
42 |
return format_response(
|
43 |
-
|
44 |
-
|
45 |
-
"page": response_data["page"],
|
46 |
-
}
|
47 |
)
|
48 |
|
49 |
@app.get("/recent")
|
@@ -62,10 +59,8 @@ async def recent(page: int = 0):
|
|
62 |
response_data = response.json()
|
63 |
|
64 |
return format_response(
|
65 |
-
|
66 |
-
|
67 |
-
"page": response_data["page"],
|
68 |
-
}
|
69 |
)
|
70 |
|
71 |
@app.get("/trending")
|
@@ -81,11 +76,9 @@ async def trending(time: str = "month", page: int = 0):
|
|
81 |
response_data = response.json()
|
82 |
|
83 |
return format_response(
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
"page": response_data["page"],
|
88 |
-
}
|
89 |
)
|
90 |
|
91 |
@app.get("/details")
|
@@ -108,7 +101,7 @@ async def details(id: str):
|
|
108 |
"tags": [tag["text"] for tag in video_data["hentai_tags"]],
|
109 |
}
|
110 |
|
111 |
-
return format_response(formatted_data)
|
112 |
|
113 |
@app.get("/link")
|
114 |
async def hentai_video(id: str):
|
@@ -119,7 +112,7 @@ async def hentai_video(id: str):
|
|
119 |
response_data = response.json()
|
120 |
|
121 |
return format_response(
|
122 |
-
|
123 |
)
|
124 |
|
125 |
@app.get("/play")
|
|
|
12 |
API_VERSION = "1.0"
|
13 |
|
14 |
# Utility function to format API responses
|
15 |
+
def format_response(**kwargs):
|
16 |
return {
|
17 |
"creator": CREATOR,
|
18 |
"api_version": API_VERSION,
|
19 |
**kwargs,
|
|
|
20 |
}
|
21 |
|
22 |
@app.get("/")
|
23 |
def root(request: Request):
|
24 |
+
return format_response(message="Welcome to the API", hostname=request.url.hostname)
|
25 |
|
26 |
@app.get("/search")
|
27 |
+
async def search(query: str, page: int = 0):
|
28 |
payload = {
|
29 |
"search_text": query,
|
30 |
"tags": [],
|
|
|
39 |
response_data = response.json()
|
40 |
|
41 |
return format_response(
|
42 |
+
results=json.loads(response_data["hits"]),
|
43 |
+
page=response_data["page"],
|
|
|
|
|
44 |
)
|
45 |
|
46 |
@app.get("/recent")
|
|
|
59 |
response_data = response.json()
|
60 |
|
61 |
return format_response(
|
62 |
+
results=json.loads(response_data["hits"]),
|
63 |
+
page=response_data["page"],
|
|
|
|
|
64 |
)
|
65 |
|
66 |
@app.get("/trending")
|
|
|
76 |
response_data = response.json()
|
77 |
|
78 |
return format_response(
|
79 |
+
results=response_data["hentai_videos"],
|
80 |
+
time=response_data["time"],
|
81 |
+
page=response_data["page"],
|
|
|
|
|
82 |
)
|
83 |
|
84 |
@app.get("/details")
|
|
|
101 |
"tags": [tag["text"] for tag in video_data["hentai_tags"]],
|
102 |
}
|
103 |
|
104 |
+
return format_response(**formatted_data)
|
105 |
|
106 |
@app.get("/link")
|
107 |
async def hentai_video(id: str):
|
|
|
112 |
response_data = response.json()
|
113 |
|
114 |
return format_response(
|
115 |
+
streams=response_data["videos_manifest"]["servers"][0]["streams"]
|
116 |
)
|
117 |
|
118 |
@app.get("/play")
|