Chrunos commited on
Commit
4f18b0f
·
verified ·
1 Parent(s): 239226a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py CHANGED
@@ -475,7 +475,49 @@ async def download_hls_video(request: Request):
475
  return {"url": download_url}
476
 
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
 
 
 
 
 
 
 
 
 
 
 
479
 
480
 
481
  @app.post("/max")
 
475
  return {"url": download_url}
476
 
477
 
478
+ @app.post("/multi")
479
+ async def multi_download(request: Request):
480
+ user_ip = get_user_ip(request)
481
+ if rate_limiter.is_rate_limited(user_ip):
482
+ current_count = rate_limiter.get_current_count(user_ip)
483
+ raise HTTPException(
484
+ status_code=429,
485
+ detail={
486
+ "error": "You have exceeded the maximum number of requests per day. Please try again tomorrow.",
487
+ "url": "https://t.me/chrunoss"
488
+ }
489
+ )
490
+ data = await request.json()
491
+ video_url = data.get('quality')
492
+ quality = data.get('url')
493
+ if quality == "mp3":
494
+ parameter = 'type=audio'
495
+ else:
496
+ parameter = f'type=video&quality={quality}'
497
+
498
+
499
+ is_youtube_url = re.search(r'(youtube\.com|youtu\.be)', video_url) is not None
500
+
501
+ if is_youtube_url:
502
+ encoded_url = urllib.parse.quote(str(video_url), safe='')
503
+ dl_url = f'https://chrunos-grab.hf.space/yt/dl?url={encoded_url}&{parameter}'
504
+ if dl_url and "http" in dl_url:
505
+ return {"url": dl_url, "requests_remaining": rate_limiter.max_requests - rate_limiter.get_current_count(user_ip)}
506
+ else:
507
+ return {
508
+ "error": "Failed to Fetch the video."
509
+ }
510
 
511
+ else:
512
+ dl_url = await get_track_download_url(video_url, quality)
513
+ if dl_url and "http" in dl_url:
514
+ return {"url": dl_url, "requests_remaining": rate_limiter.max_requests - rate_limiter.get_current_count(user_ip)}
515
+ else:
516
+ return {
517
+ "error": "Failed to Fetch the video."
518
+ }
519
+
520
+
521
 
522
 
523
  @app.post("/max")