A Telegram bot that automatically detects short video links (YouTube Shorts, TikTok, Instagram Reels), downloads the video, uploads it to the chat, and deletes the original link message.
- Link Detection: Automatically detects links to YouTube Shorts, TikTok videos, and Instagram Reels
- Video Download: Downloads videos using yt-dlp with optimized quality settings
- Auto-Upload: Uploads the downloaded video directly to the chat
- Message Cleanup: Deletes the original message containing the link
- Error Handling: Comprehensive error handling for various scenarios
- Python 3.7+
- Telegram Bot Token (from @BotFather)
- FFmpeg (for video processing)
-
Clone the repository:
git clone https://github.com/yourusername/telegram-video-bot.git cd telegram-video-bot -
Install the required dependencies:
pip install -r requirements.txt -
Install FFmpeg (if not already installed):
- Windows: Download from ffmpeg.org and add to PATH
- macOS:
brew install ffmpeg - Linux:
sudo apt install ffmpeg
-
Create a
.envfile based on the provided.env.example:cp .env.example .env -
Edit the
.envfile and add your Telegram Bot Token:BOT_TOKEN=your_telegram_bot_token_here
-
Start the bot:
python run.py -
Add the bot to a Telegram group or send a message directly to the bot with a supported video link.
-
The bot will:
- Detect the video link
- Download the video
- Upload it to the chat
- Delete the original message with the link
- YouTube Shorts
- TikTok
- Instagram Reels
You can customize the bot's behavior by modifying the .env file:
BOT_TOKEN: Your Telegram Bot TokenLOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)DOWNLOAD_DIR: Directory for temporary video storageMAX_FILE_SIZE: Maximum file size in MB (Telegram limit is 50MB)TARGET_QUALITY: Target video quality (720p recommended)
/telegram-video-bot
βββ /bot
β βββ /downloads # Temporary storage for downloaded videos
β βββ downloader.py # Video download logic
β βββ handlers.py # Message processing logic
β βββ main.py # Main bot entry point
β βββ utils.py # Utility functions (regex for links, logging)
β
βββ .env # API keys and bot token
βββ .env.example # Example environment variables
βββ requirements.txt # Dependencies
βββ run.py # Entry point script
βββ README.md # Project documentation
The bot handles various error scenarios:
- Network errors (timeout, connection refused)
- Platform API changes
- Geo-restricted content
- Video no longer available
- File size exceeding Telegram's limits
MIT