A production-ready Python CLI tool to download videos from Telegram channels
Project description
telegram-dl
A production-ready Python CLI tool to download videos from Telegram channels.
Installation
pip install telegram-dl
Quick Start
1. Get Telegram API Credentials
- Go to my.telegram.org
- Log in with your phone number
- Click "API development tools"
- Create a new app
- Copy your API ID and API Hash
2. Download Videos
# List your channels first
telegram-dl --api-id 12345 --api-hash abc123def456 --phone +1234567890 --list-channels
# Download all videos from a channel
telegram-dl --api-id 12345 --api-hash abc123def456 --phone +1234567890 --channel -1001234567890
# With progress bar
telegram-dl --api-id 12345 --api-hash abc123def456 --phone +1234567890 --channel -1001234567890 --with-progress
Programmatic Usage
from telegram_dl import TelegramDownloader, TelegramCredentials
import asyncio
async def main():
credentials = TelegramCredentials(
api_id=12345,
api_hash="abc123def456",
phone="+1234567890"
)
async with TelegramDownloader(credentials) as dl:
# List channels
channels = await dl.get_dialogs()
for ch in channels:
print(f"{ch.id} | {ch.title}")
# Download all videos
results = await dl.download_all_videos(channel_id)
asyncio.run(main())
Architecture & Design Patterns
SOLID Principles
| Principle | Implementation |
|---|---|
| Single Responsibility | Each class has one job (Client, Repository, Builder, etc.) |
| Open/Closed | Open for extension via Strategy pattern |
| Liskov Substitution | Observer and Strategy interfaces allow substitution |
| Interface Segregation | Small, focused interfaces (Observer, Repository, Factory) |
| Dependency Inversion | Depend on abstractions (Protocols) not concretions |
Design Patterns Used
1. Builder Pattern
downloader = (
DownloaderBuilder()
.with_credentials(api_id, api_hash, phone)
.with_output_dir("./videos")
.with_retry_strategy("exponential", max_attempts=5)
.with_progress_bar()
.with_logging()
.build()
)
2. Strategy Pattern
# Multiple retry strategies available
strategy = RetryStrategyFactory.create("exponential") # Exponential backoff
strategy = RetryStrategyFactory.create("fixed", delay=2.0) # Fixed delay
3. Observer Pattern
downloader.attach_observer(ProgressBarObserver())
downloader.attach_observer(LoggingObserver())
4. Repository Pattern
repo = VideoRepository(client, channel_entity)
videos = await repo.get_all()
video = await repo.get_by_id(123)
5. Factory Pattern
config = ConfigFactory.create_download_config(output_dir="./videos")
strategy = RetryStrategyFactory.create("exponential", max_attempts=3)
Data Models (Pydantic)
All data models use Pydantic v2 for:
- Type validation
- Serialization
- Documentation
from telegram_dl.models import VideoMetadata, DownloadProgress, DownloadResult
# All models are fully typed and validated
video = VideoMetadata(id=1, name="video.mp4", size=1024)
Features
- Production-Ready: Comprehensive error handling, logging, retries
- Type Safe: Full type hints with Pydantic validation
- Design Patterns: Builder, Factory, Observer, Repository, Strategy
- SOLID Principles: Clean, maintainable, extensible code
- Progress Tracking: Real-time progress bars and logging
- Retry Logic: Multiple retry strategies with backoff
Publishing Guide
Manual Publishing to PyPI
# 1. Install build tools
pip install build twine
# 2. Update version in pyproject.toml
# version = "2.0.0"
# 3. Build the package
rm -rf dist/
python -m build
# 4. Upload to PyPI
twine upload dist/*
Requirements
- Python 3.10+
- Telegram API credentials (get from my.telegram.org)
- Dependencies: telethon, pydantic, tenacity, tqdm
Links
- PyPI Package: https://pypi.org/project/telegram-dl/
- GitHub Repository: https://github.com/kuldeep27396/telegram-dl
- Report Issues: https://github.com/kuldeep27396/telegram-dl/issues
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
telegram_dl-2.0.0.tar.gz
(17.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telegram_dl-2.0.0.tar.gz.
File metadata
- Download URL: telegram_dl-2.0.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75e5114a627f75b3178d432df72641f08b4f454ffd46d75d768f178968e827c3
|
|
| MD5 |
ac75077afd560e9a253d43a5ae687706
|
|
| BLAKE2b-256 |
49f541ff8f718940cce0d18a87b9589194bf6dbd040ef7635a6de71989f1bdee
|
File details
Details for the file telegram_dl-2.0.0-py3-none-any.whl.
File metadata
- Download URL: telegram_dl-2.0.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
522ad10ee88c3e3f8a5c1410b8d99c3f2534901685fa08a15871181a0e69c726
|
|
| MD5 |
5d8637ec72d1db4799f9877c4953b515
|
|
| BLAKE2b-256 |
4a5f61cb7085df0ce020cbbff00816e5873deac6c47bd24540590f35dbba22d0
|