Overview
The script uses Telethon (Telegramβs official Python API client) for downloading files from Telegram. This works for both public and private channels you have access to.Telegram integration is optional. You only need it if you want to download files from Telegram channels/groups.
Why Telethon?
Telegram doesnβt use traditional web cookies for authentication. Private channels require Telegramβs native API with session-based auth. Telethon vs yt-dlp:| Feature | Telethon | yt-dlp |
|---|---|---|
| Public channels | β Works | β Works (sometimes) |
| Private channels | β Works | β Fails |
| Authentication | β Session-based | β Cookie-based |
| Media downloads | β All types | β Metadata only |
Prerequisites
Python 3.7+
Check version:
python3 --versionTelethon Library
Install:
pip install telethonTelegram API Credentials
Get from: https://my.telegram.org
Telegram Account
Phone number for authentication
Installation
Step 1: Install Telethon
1.24.0.
Step 2: Get Telegram API Credentials
Go to my.telegram.org
Open https://my.telegram.org in your browser
Create application
Click on βAPI development toolsβFill in the form:Click βCreate applicationβ
Step 3: Configure Environment Variables
- Option 1: .env File (Recommended)
- Option 2: Shell Profile
- Option 3: Temporary
Add to your The script will automatically load these from
.env file:.env
.env.First Run - Authentication
The first time you download from Telegram, youβll be prompted to authenticate:The authentication session is valid indefinitely. You wonβt need to enter your phone/code again unless you delete the session file.
Usage
Once set up, Telegram links work just like any other URL:Single File
Multiple Files
With Folder Selection
Mixed URLs
Supported Formats
- Public Channels
- Private Channels
- Media Types
Download Progress
Telegram downloads show real-time progress:Troubleshooting
TELEGRAM_API_ID and TELEGRAM_API_HASH required
TELEGRAM_API_ID and TELEGRAM_API_HASH required
Error:Solution:
- Get credentials from https://my.telegram.org
- Add to
.envfile or export as environment variables - See Step 3: Configure Environment Variables
ERROR: Message not found
ERROR: Message not found
Possible causes:
- The message doesnβt exist
- Message was deleted
- You donβt have access to the channel
- The link is incorrect
- Verify the link is correct
- Check if youβre a member of private channels
- Try opening the link in Telegram app first
ERROR: No media in message
ERROR: No media in message
Cause:
The Telegram message is text-only (no file attached).Solution:
Make sure the message contains a file. Text-only posts canβt be downloaded.
database is locked
database is locked
Cause:
Session file is locked by another process or crashed session.Solution:Or fully reset:Next run will prompt for authentication again.
Session authentication issues
Session authentication issues
Symptoms:Enter phone number and verification code when prompted.
- Keeps asking for phone number
- βUser is deactivatedβ error
- Random authentication failures
Telethon not installed
Telethon not installed
Error:Solution:Verify:
You don't have access to this channel
You don't have access to this channel
Cause:
Private channel requires membership.Solution:
- Join the channel in your Telegram app
- Make sure youβre logged in with the same phone number
- Try downloading again
Security Notes
Session file location:Setup Helper Script
Use the interactive setup helper:- Check for Python and Telethon
- Prompt for API credentials
- Save to
.envfile - Test the configuration
Example Session
Advanced Usage
Download Entire Channel
While the script doesnβt support bulk channel downloads, you can create a JSON file with message links:urls.json
Rate Limiting
Telegram API has rate limits. If youβre downloading many files:- Recommended: Process 10-20 files at a time
- Wait time: 1-2 seconds between files (automatic)
- Daily limit: ~1000 files per day per account
Next Steps
Usage Examples
See real-world Telegram usage patterns
Interactive Features
Master the interactive UI
File Organization
Understand how files are organized
Troubleshooting
Fix common issues