Download !!top!!er Telegram Bot | Youtube

[Install] WantedBy=multi-user.target Create a Procfile :

# Send info message status_msg = await update.message.reply_text("🔍 *Analyzing video...*", parse_mode='Markdown') youtube downloader telegram bot

try: if action == "audio": # Download audio with yt_dlp.YoutubeDL(YDL_OPTS_AUDIO) as ydl: info = ydl.extract_info(url, download=True) filename = ydl.prepare_filename(info).replace('.webm', '.mp3').replace('.m4a', '.mp3') # Send audio file with open(filename, 'rb') as audio_file: await context.bot.send_audio( chat_id=query.message.chat_id, audio=audio_file, title=info.get('title', 'Audio'), performer=info.get('uploader', 'YouTube'), duration=info.get('duration', 0) ) # Cleanup os.remove(filename) elif action == "video": # Download video with yt_dlp.YoutubeDL(YDL_OPTS_VIDEO) as ydl: info = ydl.extract_info(url, download=True) filename = ydl.prepare_filename(info) # Send video file (Telegram limit: 50MB) file_size = os.path.getsize(filename) / (1024 * 1024) if file_size > 50: await query.edit_message_text( f"❌ Video file is too large ({file_size:.1f}MB). Telegram limit is 50MB.\n" f"Try downloading audio instead." ) else: with open(filename, 'rb') as video_file: await context.bot.send_video( chat_id=query.message.chat_id, video=video_file, caption=f"📹 {info.get('title', 'Video')}", supports_streaming=True ) # Cleanup os.remove(filename) # Send success message await context.bot.send_message( chat_id=query.message.chat_id, text="✅ *Download complete!*\n\nSend another YouTube URL to continue.", parse_mode='Markdown' ) # Clear user data del user_data[user_id] except Exception as e: logger.error(f"Download error: {e}") await query.edit_message_text(f"❌ Download failed: {str(e)[:200]}") if user_id in user_data: del user_data[user_id] async def error_handler(update: Update, context: ContextTypes.DEFAULT_TYPE): logger.error(f"Update {update} caused error {context.error}") [Install] WantedBy=multi-user

Build and run:

COPY bot.py .