Spaces:
Running
Running
Delete tools.py
Browse files
tools.py
DELETED
@@ -1,197 +0,0 @@
|
|
1 |
-
import io
|
2 |
-
import requests
|
3 |
-
import os
|
4 |
-
import re
|
5 |
-
import uuid
|
6 |
-
from PIL import Image, ImageEnhance
|
7 |
-
from fastapi import APIRouter, Depends
|
8 |
-
from fastapi.responses import StreamingResponse
|
9 |
-
from fastapi import UploadFile
|
10 |
-
from fastapi import *
|
11 |
-
from fastapi.responses import *
|
12 |
-
from fastapi.responses import JSONResponse
|
13 |
-
from fastapi import HTTPException
|
14 |
-
from dotenv import load_dotenv
|
15 |
-
from pydantic import BaseModel
|
16 |
-
from pymongo import MongoClient
|
17 |
-
from models import *
|
18 |
-
from RyuzakiLib import AsyicXSearcher
|
19 |
-
|
20 |
-
load_dotenv()
|
21 |
-
TOOLS_NEW_URL = os.environ["TOOLS_NEW_URL"]
|
22 |
-
MONGO_URL = os.environ["MONGO_URL"]
|
23 |
-
|
24 |
-
client_mongo = MongoClient(MONGO_URL)
|
25 |
-
db = client_mongo["tiktokbot"]
|
26 |
-
collection = db["users"]
|
27 |
-
|
28 |
-
router = APIRouter()
|
29 |
-
|
30 |
-
class XnxxSearch(BaseModel):
|
31 |
-
q: str
|
32 |
-
|
33 |
-
class XnxxLinks(BaseModel):
|
34 |
-
url: str
|
35 |
-
|
36 |
-
def get_all_api_keys():
|
37 |
-
user = collection.find({})
|
38 |
-
api_keys = []
|
39 |
-
for x in user:
|
40 |
-
api_key = x.get("ryuzaki_api_key")
|
41 |
-
if api_key:
|
42 |
-
api_keys.append(api_key)
|
43 |
-
return api_keys
|
44 |
-
|
45 |
-
def validate_api_key(api_key: str = Header(...)):
|
46 |
-
USERS_API_KEYS = get_all_api_keys()
|
47 |
-
if api_key not in USERS_API_KEYS:
|
48 |
-
raise HTTPException(status_code=401, detail="Invalid API key")
|
49 |
-
|
50 |
-
async def tools_search(
|
51 |
-
name=None,
|
52 |
-
parameter=None,
|
53 |
-
ai_model=None,
|
54 |
-
upload_check=False
|
55 |
-
):
|
56 |
-
if upload_check:
|
57 |
-
TOOLS_API_URL = f"{TOOLS_NEW_URL}/{ai_model}/{parameter}"
|
58 |
-
return TOOLS_API_URL
|
59 |
-
else:
|
60 |
-
TOOLS_API_URL = f"{TOOLS_NEW_URL}/tools/{name}?{parameter}"
|
61 |
-
return TOOLS_API_URL
|
62 |
-
|
63 |
-
async def toanime(input):
|
64 |
-
url = await tools_search(
|
65 |
-
ai_model="ai",
|
66 |
-
parameter="toanime",
|
67 |
-
upload_check=True
|
68 |
-
)
|
69 |
-
try:
|
70 |
-
image = Image.open(input)
|
71 |
-
buffer = io.BytesIO()
|
72 |
-
image.save(buffer, format='JPEG')
|
73 |
-
buffer.seek(0)
|
74 |
-
files = {
|
75 |
-
'image': ('toanime.jpg', buffer, 'image/jpeg')
|
76 |
-
}
|
77 |
-
response = requests.post(
|
78 |
-
url,
|
79 |
-
files=files,
|
80 |
-
headers={
|
81 |
-
'accept': 'application/json'
|
82 |
-
}
|
83 |
-
)
|
84 |
-
if response.status_code == 200:
|
85 |
-
data = response.json()
|
86 |
-
res = {
|
87 |
-
"image_data": data['result'],
|
88 |
-
"image_size": data['size']
|
89 |
-
}
|
90 |
-
return res
|
91 |
-
else:
|
92 |
-
return 'Identifikasi Gagal'
|
93 |
-
except Exception:
|
94 |
-
return 'Identifikasi Gagal'
|
95 |
-
|
96 |
-
@router.post("/akeno/toanime", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
97 |
-
async def toanime_endpoint(
|
98 |
-
file: UploadFile = File(...),
|
99 |
-
api_key: str = Depends(validate_api_key)
|
100 |
-
):
|
101 |
-
file_path = f"./uploads/{file.filename}"
|
102 |
-
try:
|
103 |
-
with open(file_path, "wb") as f:
|
104 |
-
f.write(await file.read())
|
105 |
-
except Exception:
|
106 |
-
raise HTTPException(status_code=500, detail="Failed to save file")
|
107 |
-
try:
|
108 |
-
response = await toanime(file_path)
|
109 |
-
url_image = response["image_data"]
|
110 |
-
return SuccessResponse(
|
111 |
-
status="True",
|
112 |
-
randydev={"url": url_image}
|
113 |
-
)
|
114 |
-
except Exception:
|
115 |
-
return SuccessResponse(
|
116 |
-
status="False",
|
117 |
-
randydev={"error": "Error during processing"}
|
118 |
-
)
|
119 |
-
finally:
|
120 |
-
if os.path.exists(file_path):
|
121 |
-
os.remove(file_path)
|
122 |
-
|
123 |
-
@router.post("/akeno/xnxxsearch", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
124 |
-
async def xnxx_search(
|
125 |
-
payload: XnxxSearch,
|
126 |
-
api_key: None = Depends(validate_api_key)
|
127 |
-
):
|
128 |
-
url = await tools_search(name="xnxxsearch", parameter=f"q={payload.query}")
|
129 |
-
try:
|
130 |
-
response = await AsyicXSearcher.search(url, re_json=True)
|
131 |
-
result = response["result"]
|
132 |
-
return SuccessResponse(
|
133 |
-
status="True",
|
134 |
-
randydev={"results": result}
|
135 |
-
)
|
136 |
-
except:
|
137 |
-
return SuccessResponse(
|
138 |
-
status="False",
|
139 |
-
randydev={"error": "Error fucking"}
|
140 |
-
)
|
141 |
-
|
142 |
-
@router.post("/akeno/xnxx-dl", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
143 |
-
async def xnxx_download(
|
144 |
-
payload: XnxxLinks,
|
145 |
-
api_key: None = Depends(validate_api_key)
|
146 |
-
):
|
147 |
-
url = await tools_search(name="xnxxdl", parameter=f"url={payload.link}")
|
148 |
-
try:
|
149 |
-
response = await AsyicXSearcher.search(url, re_json=True)
|
150 |
-
result = response["result"]
|
151 |
-
return SuccessResponse(
|
152 |
-
status="True",
|
153 |
-
randydev={"results": result}
|
154 |
-
)
|
155 |
-
except:
|
156 |
-
return SuccessResponse(
|
157 |
-
status="False",
|
158 |
-
randydev={"error": "Error fucking"}
|
159 |
-
)
|
160 |
-
|
161 |
-
@router.post("/akeno/xnxx-videodl", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
162 |
-
async def xnxx_videodl(
|
163 |
-
payload: XnxxLinks,
|
164 |
-
api_key: None = Depends(validate_api_key)
|
165 |
-
):
|
166 |
-
url = await tools_search(name="xvideosdl", parameter=f"url={payload.link}")
|
167 |
-
try:
|
168 |
-
response = await AsyicXSearcher.search(url, re_json=True)
|
169 |
-
result = response["result"]
|
170 |
-
return SuccessResponse(
|
171 |
-
status="True",
|
172 |
-
randydev={"results": result}
|
173 |
-
)
|
174 |
-
except:
|
175 |
-
return SuccessResponse(
|
176 |
-
status="False",
|
177 |
-
randydev={"error": "Error fucking"}
|
178 |
-
)
|
179 |
-
|
180 |
-
@router.post("/akeno/instagramdl", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
181 |
-
async def instagramdl(
|
182 |
-
payload: XnxxLinks,
|
183 |
-
api_key: None = Depends(validate_api_key)
|
184 |
-
):
|
185 |
-
url = await tools_search(name="instagramdl", parameter=f"url={payload.link}")
|
186 |
-
try:
|
187 |
-
response = await AsyicXSearcher.search(url, re_json=True)
|
188 |
-
result = response["result"]
|
189 |
-
return SuccessResponse(
|
190 |
-
status="True",
|
191 |
-
randydev={"results": result}
|
192 |
-
)
|
193 |
-
except:
|
194 |
-
return SuccessResponse(
|
195 |
-
status="False",
|
196 |
-
randydev={"error": "Error fucking"}
|
197 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|