Celeskry commited on
Commit
d728620
·
verified ·
1 Parent(s): 873a039

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +47 -3
main.py CHANGED
@@ -22,6 +22,8 @@ from app.ht_noti import HentaiApp
22
  from app.ios_app import IOSAppFetcher
23
  from app.tik_dl import TiktokDl
24
  from app.tik_cdn import TiktokCdn
 
 
25
  from app.byps_uv import BypassUV
26
  from app.gs_code import GSCodeApp
27
  from app.gm_crate import GmailLogic
@@ -36,6 +38,8 @@ bypass_app = BypassUV()
36
  tik_app = TiktokDl()
37
  tik_direct = TiktokCdn()
38
  hentai_app = HentaiApp()
 
 
39
  ios_app = IOSAppFetcher()
40
  gs_code_app = GSCodeApp()
41
  invite_app = DiscordInviteLogic()
@@ -79,13 +83,13 @@ async def lifespan(app: FastAPI):
79
  await asyncio.gather(
80
  invite_app.start(), lq_app.start(), gs_app.start(),
81
  gs_code_app.start(), hentai_app.start(), ht_random_app.start(),
82
- bypass_app.start(), ios_app.start(), xs_app.start(), tik_direct.start()
83
  )
84
  yield
85
  await asyncio.gather(
86
  invite_app.stop(), lq_app.stop(), gs_app.stop(),
87
  gs_code_app.stop(), hentai_app.stop(), ht_random_app.stop(),
88
- bypass_app.stop(), ios_app.stop(), xs_app.stop(), tik_direct.stop()
89
  )
90
 
91
  app = FastAPI(lifespan=lifespan)
@@ -262,7 +266,47 @@ async def tiktok_cdn(
262
  headers={"Content-Disposition": f"attachment; filename=Celeste_{int(time.time())}.{media_type_req}"}
263
  )
264
 
265
- raise HTTPException(status_code=400, detail="Provide either 'url' or 'token'")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  @app.get("/api/v1/bypass")
268
  async def bypass_link(url: str = Query(...), apikey: Optional[str] = Query(None), x_api_key: Optional[str] = Header(None, alias="X-API-Key")):
 
22
  from app.ios_app import IOSAppFetcher
23
  from app.tik_dl import TiktokDl
24
  from app.tik_cdn import TiktokCdn
25
+ from app.yt_dl import YouTubeDl
26
+ from app.yt_cdn import YouTubeCdn
27
  from app.byps_uv import BypassUV
28
  from app.gs_code import GSCodeApp
29
  from app.gm_crate import GmailLogic
 
38
  tik_app = TiktokDl()
39
  tik_direct = TiktokCdn()
40
  hentai_app = HentaiApp()
41
+ yt_app = YouTubeDl()
42
+ yt_cdn = YouTubeCdn()
43
  ios_app = IOSAppFetcher()
44
  gs_code_app = GSCodeApp()
45
  invite_app = DiscordInviteLogic()
 
83
  await asyncio.gather(
84
  invite_app.start(), lq_app.start(), gs_app.start(),
85
  gs_code_app.start(), hentai_app.start(), ht_random_app.start(),
86
+ bypass_app.start(), ios_app.start(), xs_app.start(), tik_direct.start(), yt_cdn.start())
87
  )
88
  yield
89
  await asyncio.gather(
90
  invite_app.stop(), lq_app.stop(), gs_app.stop(),
91
  gs_code_app.stop(), hentai_app.stop(), ht_random_app.stop(),
92
+ bypass_app.stop(), ios_app.stop(), xs_app.stop(), tik_direct.stop(), yt_cdn.stop())
93
  )
94
 
95
  app = FastAPI(lifespan=lifespan)
 
266
  headers={"Content-Disposition": f"attachment; filename=Celeste_{int(time.time())}.{media_type_req}"}
267
  )
268
 
269
+ raise HTTPException(status_code=400, detail="Provide either 'url' or '
270
+
271
+ @app.get("/api/v1/youtube/dl")
272
+ async def youtube_dl(
273
+ url: str = Query(...),
274
+ format: str = Query("1080"),
275
+ apikey: Optional[str] = Query(None),
276
+ x_api_key: Optional[str] = Header(None, alias="X-API-Key")
277
+ ):
278
+ key = x_api_key or apikey
279
+ if not API_KEY or key != API_KEY:
280
+ raise HTTPException(status_code=403, detail="API key invalid")
281
+
282
+ return await yt_app.fetch_info(url, yt_cdn, format)
283
+
284
+ @app.get("/api/v1/youtube/cdn")
285
+ async def youtube_cdn_proxy(
286
+ token: str = Query(...),
287
+ ):
288
+ data = yt_cdn.consume_token(token)
289
+ if not data:
290
+ raise HTTPException(status_code=404, detail="Token invalid or expired")
291
+
292
+ async def stream_file():
293
+ async with httpx.AsyncClient(follow_redirects=True, timeout=120.0) as client:
294
+ async with client.stream("GET", data["url"]) as r:
295
+ async for chunk in r.aiter_bytes(chunk_size=1024*1024):
296
+ yield chunk
297
+
298
+ media_types = {
299
+ "mp4": "video/mp4",
300
+ "mp3": "audio/mpeg",
301
+ "wav": "audio/wav",
302
+ "jpg": "image/jpeg"
303
+ }
304
+
305
+ return StreamingResponse(
306
+ stream_file(),
307
+ media_type=media_types.get(data["type"], "application/octet-stream"),
308
+ headers={"Content-Disposition": f"attachment; filename=Celeskry_YT_{int(time.time())}.{data['type']}"}
309
+ )
310
 
311
  @app.get("/api/v1/bypass")
312
  async def bypass_link(url: str = Query(...), apikey: Optional[str] = Query(None), x_api_key: Optional[str] = Header(None, alias="X-API-Key")):