Update app.py
Browse files219 unmodified lines220221222219 unmodified linesdownload_url = f"{base_url}file/{encoded_filename}"gc.collect()return {"url": download_url}219 unmodified lines220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289219 unmodified linesdownload_url = f"{base_url}file/{encoded_filename}"gc.collect()return {"url": download_url}@app.post("/maxs")async def download_high_quality_video(request: Request):user_ip = get_user_ip(request)if rate_limiter.is_rate_limited(user_ip):current_count = rate_limiter.get_current_count(user_ip)raise HTTPException(status_code=429,detail={"error": "You have exceeded the maximum number of requests per day. Please try again tomorrow.","url": "https://t.me/chrunoss"})data = await request.json()video_url = data.get('url')if "t.me" in video_url or "chrunos.com" in video_url:return {"error": f"{video_url} is not supported", "url": "https://t.me/chrunoss"}quality = data.get('quality', '720') # Default to 720 if not specifiedlogger.info(f'input: {video_url}, {quality}')# Check if the requested quality is above 1080pif int(quality) > 720:error_message = "Quality above 720p is for Premium Members Only. Please check the URL for more information."help_url = "https://chrunos.com/premium-shortcuts/" # Replace with your actual URLreturn {"error": error_message, "url": help_url}timestamp = datetime.now().strftime('%Y%m%d%H%M%S')output_template = str(Path(global_download_dir) / f'%(title).70s_{timestamp}.%(ext)s')# Convert quality string to heightheight_map = {'480': 480,'720': 720,'1080': 1080}max_height = height_map.get(quality, 1080) # Use the quality variable correctly# Determine format string based on qualityformat_str = f'bestvideo[height<={max_height}][vcodec^=avc]+bestaudio/best'ydl_opts = {'format': format_str,'outtmpl': output_template,'quiet': True,'no_warnings': True,'noprogress': True,'merge_output_format': 'mp4'}await run_in_threadpool(lambda: yt_dlp.YoutubeDL(ydl_opts).download([video_url]))downloaded_files = list(Path(global_download_dir).glob(f"*_{timestamp}.mp4"))if not downloaded_files:return {"error": "Download failed. Report error on Telegram", "url": "https://t.me/chrunoss"}downloaded_file = downloaded_files[0]encoded_filename = urllib.parse.quote(downloaded_file.name)download_url = f"{BASE_URL}/file/{encoded_filename}"gc.collect()return {"url": download_url}
app.py+67