Celeskry commited on
Commit
63d2bb7
·
verified ·
1 Parent(s): 100b995

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +42 -28
main.py CHANGED
@@ -25,6 +25,7 @@ from app.gs_code import GSCodeApp
25
  from app.gm_crate import GmailLogic
26
  from app.gs_daily import GSDailyApp
27
  from app.invite_logic import DiscordInviteLogic
 
28
 
29
  xs_app = XoSoApp()
30
  lq_app = ClLqApp()
@@ -32,6 +33,7 @@ gm_app = GmailLogic()
32
  gs_app = GSDailyApp()
33
  bypass_app = BypassUV()
34
  tik_app = TikTokDownloader()
 
35
  hentai_app = HentaiApp()
36
  ios_app = IOSAppFetcher()
37
  gs_code_app = GSCodeApp()
@@ -76,13 +78,13 @@ async def lifespan(app: FastAPI):
76
  await asyncio.gather(
77
  invite_app.start(), lq_app.start(), gs_app.start(),
78
  gs_code_app.start(), hentai_app.start(), ht_random_app.start(),
79
- bypass_app.start(), ios_app.start(), xs_app.start(), tik_app.start()
80
  )
81
  yield
82
  await asyncio.gather(
83
  invite_app.stop(), lq_app.stop(), gs_app.stop(),
84
  gs_code_app.stop(), hentai_app.stop(), ht_random_app.stop(),
85
- bypass_app.stop(), ios_app.stop(), xs_app.stop(), tik_app.stop()
86
  )
87
 
88
  app = FastAPI(lifespan=lifespan)
@@ -163,42 +165,54 @@ async def hentai_random(apikey: Optional[str] = Query(None), limit: str = Query(
163
  return await ht_random_app.get_random(key, API_KEY, limit)
164
 
165
  @app.get("/api/v1/tiktok/download")
166
- async def tiktok_download(url: str = Query(...), apikey: Optional[str] = Query(None)):
167
- if apikey != API_KEY:
168
- raise HTTPException(status_code=403, detail="Key sai rồi")
 
169
 
170
- res = await tik_app.fetch_video_info(url)
171
  if not res["ok"]:
172
  raise HTTPException(status_code=400, detail=res["error"])
173
  return res
174
 
175
  @app.get("/api/v1/tiktok/dl-direct")
176
- async def tiktok_direct_handler(token: str = Query(...)):
177
- # KHÔNG CẦN API KEY Ở ĐÂY
178
-
179
- real_url = await tik_app.get_real_stream_url(token)
180
-
181
- if real_url == "limit_exceeded":
182
- raise HTTPException(status_code=403, detail="Link này đã hết lượt tải (Max 3 lần)")
183
- if not real_url:
184
- raise HTTPException(status_code=404, detail="Không tìm thấy file hoặc token hết hạn")
 
185
 
186
- async def stream():
187
- async with httpx.AsyncClient() as client:
188
- async with client.stream("GET", real_url) as r:
189
- async for chunk in r.aiter_bytes():
190
- yield chunk
191
 
192
- # Tự động lấy type từ cache dựa trên token
193
- media_type = tik_app.token_cache[token]["type"]
194
- filename = f"celeste_{int(time.time())}.{media_type}"
 
195
 
196
- return StreamingResponse(
197
- stream(),
198
- media_type="video/mp4" if media_type == "mp4" else "audio/mpeg",
199
- headers={"Content-Disposition": f"attachment; filename={filename}"}
200
- )
 
 
 
 
 
 
 
 
201
 
 
202
 
203
  @app.get("/api/v1/bypass")
204
  async def bypass_link(url: str = Query(...), apikey: Optional[str] = Query(None), x_api_key: Optional[str] = Header(None, alias="X-API-Key")):
 
25
  from app.gm_crate import GmailLogic
26
  from app.gs_daily import GSDailyApp
27
  from app.invite_logic import DiscordInviteLogic
28
+ from app.tik_dldrct import TikTokDirect
29
 
30
  xs_app = XoSoApp()
31
  lq_app = ClLqApp()
 
33
  gs_app = GSDailyApp()
34
  bypass_app = BypassUV()
35
  tik_app = TikTokDownloader()
36
+ tik_direct = TikTokDirect()
37
  hentai_app = HentaiApp()
38
  ios_app = IOSAppFetcher()
39
  gs_code_app = GSCodeApp()
 
78
  await asyncio.gather(
79
  invite_app.start(), lq_app.start(), gs_app.start(),
80
  gs_code_app.start(), hentai_app.start(), ht_random_app.start(),
81
+ bypass_app.start(), ios_app.start(), xs_app.start(), tik_direct.start()
82
  )
83
  yield
84
  await asyncio.gather(
85
  invite_app.stop(), lq_app.stop(), gs_app.stop(),
86
  gs_code_app.stop(), hentai_app.stop(), ht_random_app.stop(),
87
+ bypass_app.stop(), ios_app.stop(), xs_app.stop(), tik_direct.stop()
88
  )
89
 
90
  app = FastAPI(lifespan=lifespan)
 
165
  return await ht_random_app.get_random(key, API_KEY, limit)
166
 
167
  @app.get("/api/v1/tiktok/download")
168
+ async def tiktok_download(url: str = Query(...), hd: int = Query(1), apikey: Optional[str] = Query(None), x_api_key: Optional[str] = Header(None, alias="X-API-Key")):
169
+ key = x_api_key or apikey
170
+ if not API_KEY or key != API_KEY:
171
+ raise HTTPException(status_code=403, detail="API key invalid. Go touch grass")
172
 
173
+ res = await tik_app.fetch_video(url, hd)
174
  if not res["ok"]:
175
  raise HTTPException(status_code=400, detail=res["error"])
176
  return res
177
 
178
  @app.get("/api/v1/tiktok/dl-direct")
179
+ async def tiktok_direct(
180
+ url: str = Query(None),
181
+ token: str = Query(None),
182
+ type: str = Query("mp4"),
183
+ apikey: Optional[str] = Query(None),
184
+ x_api_key: Optional[str] = Header(None, alias="X-API-Key")
185
+ ):
186
+ key = x_api_key or apikey
187
+ if not API_KEY or key != API_KEY:
188
+ raise HTTPException(status_code=403, detail="API key invalid")
189
 
190
+ if url:
191
+ res = await tik_direct.generate_token(url, type)
192
+ if not res["ok"]:
193
+ raise HTTPException(status_code=400, detail=res["error"])
194
+ return res
195
 
196
+ if token:
197
+ data = tik_direct.get_token_data(token)
198
+ if not data:
199
+ raise HTTPException(status_code=404, detail="Token expired or invalid")
200
 
201
+ async def stream():
202
+ async with httpx.AsyncClient() as client:
203
+ async with client.stream("GET", data["url"]) as r:
204
+ async for chunk in r.aiter_bytes():
205
+ yield chunk
206
+
207
+ filename = f"tiktok_{int(time.time())}.{data['type']}"
208
+
209
+ return StreamingResponse(
210
+ stream(),
211
+ media_type="video/mp4" if data["type"] == "mp4" else "audio/mpeg",
212
+ headers={"Content-Disposition": f"attachment; filename={filename}"}
213
+ )
214
 
215
+ raise HTTPException(status_code=400, detail="Missing url or token")
216
 
217
  @app.get("/api/v1/bypass")
218
  async def bypass_link(url: str = Query(...), apikey: Optional[str] = Query(None), x_api_key: Optional[str] = Header(None, alias="X-API-Key")):