A Telegram bot that can download videos from YouTube, Instagram, and Twitter/X using yt-dlp.
- Downloads videos from YouTube, Instagram, and Twitter/X
- Automatically handles different video formats
- Respects Telegram's file size limitations
- User access control with allowlist
- Easy to set up and deploy
- Can be run as a Docker container
- Python 3.7+
- A Telegram Bot Token (obtained from BotFather)
- yt-dlp and other dependencies
-
Clone this repository:
git clone <repository-url> cd videodlbot -
Install dependencies:
pip install -r requirements.txt -
Set up your environment variables by editing the
.envfile:TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here ALLOWED_USERS=your_telegram_user_id_here # Comma-separated list of allowed user IDs MAX_FILE_SIZE=52428800 # Optional: Max file size in bytes (default: 50MB)
- Open Telegram and search for @BotFather
- Start a chat with BotFather and use the
/newbotcommand - Follow the instructions to create a new bot
- Once created, BotFather will provide you with a token - copy this into your
.envfile
To find your Telegram User ID:
- Start a chat with @userinfobot
- The bot will reply with your user ID
- Copy this ID into the
ALLOWED_USERSfield in your.envfile - For multiple users, separate IDs with commas (e.g.,
123456789,987654321)
Start the bot with:
python main.py
The bot will run until you terminate the process (Ctrl+C).
- Start a chat with your bot on Telegram
- Send a URL from YouTube, Instagram, or Twitter/X
- The bot will download the video and send it back to you
Note: Only users whose Telegram IDs are listed in the ALLOWED_USERS setting will be able to use the bot. This helps prevent unauthorized usage.
/start- Introduces the bot and explains its functionality/help- Shows usage instructions
- Due to Telegram API limitations, videos larger than 50MB cannot be sent
- Some websites may implement anti-scraping measures that could prevent downloads
- Access is restricted to users specified in the
ALLOWED_USERSsetting for security
For 24/7 operation, consider deploying the bot on a cloud platform or a VPS.
You can easily run this bot as a Docker container. We provide both a Docker Compose setup and a convenience script for managing the Docker container.
The easiest way to run the bot in Docker is with the included helper script:
-
Make the script executable:
chmod +x docker-run.sh -
Copy the environment file:
cp .env.docker.sample .env -
Edit the
.envfile to add your Telegram Bot Token, your Telegram User ID in theALLOWED_USERSsetting, and adjust any other settings. -
Run the bot:
./docker-run.sh start -
View logs:
./docker-run.sh logs -
Stop the bot:
./docker-run.sh stop -
Show all available commands:
./docker-run.sh help
If you prefer to use Docker Compose commands directly:
-
Copy the environment file:
cp .env.docker.sample .env -
Edit the
.envfile to add your Telegram Bot Token and User ID. -
Build and start the container:
docker-compose up -d -
Stop the container:
docker-compose down -
View logs:
docker-compose logs -f
If you prefer to use Docker without docker-compose:
-
Build the Docker image:
docker build -t videodlbot . -
Run the container:
docker run -d --name videodlbot \ -e TELEGRAM_BOT_TOKEN=your_token_here \ -e ALLOWED_USERS=your_user_id_here \ -e MAX_FILE_SIZE=1073741824 \ -e DEBUG_MODE=false \ -v $(pwd)/downloads:/app/downloads \ -v $(pwd)/cookies.txt:/app/cookies.txt:ro \ videodlbot
The Docker setup uses a volume for downloads to persist downloaded files between container restarts. If you need to use cookies for authentication with certain sites:
- Create a
cookies.txtfile in the project directory. - Set
USE_COOKIES=truein your.envfile.
The cookies file will be mounted as read-only inside the container.
- If you encounter SSL or network errors, ensure your server has the latest CA certificates
- If videos fail to download, check if yt-dlp needs to be updated:
pip install -U yt-dlp
This project is licensed under the MIT License - see the LICENSE file for details.