Update app.py
Browse files
app.py
CHANGED
@@ -591,6 +591,17 @@ async def download_audio(
|
|
591 |
request: Request
|
592 |
#api_key: str = Security(verify_api_key)
|
593 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
data = await request.json()
|
595 |
video_url = data.get('url')
|
596 |
#cookiefile = "firefox-cookies.txt"
|
@@ -633,7 +644,7 @@ async def download_audio(
|
|
633 |
encoded_filename = urllib.parse.quote(downloaded_file.name)
|
634 |
download_url = f"{BASE_URL}/file/{encoded_filename}"
|
635 |
gc.collect()
|
636 |
-
return {"url": download_url}
|
637 |
|
638 |
# Configure logging
|
639 |
logging.basicConfig(level=logging.INFO)
|
|
|
591 |
request: Request
|
592 |
#api_key: str = Security(verify_api_key)
|
593 |
):
|
594 |
+
user_ip = get_user_ip(request)
|
595 |
+
|
596 |
+
if rate_limiter.is_rate_limited(user_ip):
|
597 |
+
current_count = rate_limiter.get_current_count(user_ip)
|
598 |
+
raise HTTPException(
|
599 |
+
status_code=429,
|
600 |
+
detail={
|
601 |
+
"error": "You have exceeded the maximum number of requests per day. Please try again tomorrow.",
|
602 |
+
"url": "https://t.me/chrunoss"
|
603 |
+
}
|
604 |
+
)
|
605 |
data = await request.json()
|
606 |
video_url = data.get('url')
|
607 |
#cookiefile = "firefox-cookies.txt"
|
|
|
644 |
encoded_filename = urllib.parse.quote(downloaded_file.name)
|
645 |
download_url = f"{BASE_URL}/file/{encoded_filename}"
|
646 |
gc.collect()
|
647 |
+
return {"url": download_url, "requests_remaining": rate_limiter.max_requests - rate_limiter.get_current_count(user_ip)}
|
648 |
|
649 |
# Configure logging
|
650 |
logging.basicConfig(level=logging.INFO)
|