Skip to main content

A high-performance CLI tool for downloading media from Telegram

Project description

๐Ÿš€ Telegram Media Downloader - tgdl

GitHub Repo stars GitHub watchers GitHub forks GitHub License PyPI - Downloads PyPI - Format PyPI - Status PyPI version Python versions

A powerful, high-performance CLI tool for downloading media from Telegram channels, groups, bot chats, and messages. Built with async/await for 5-10x faster downloads with smart filters and progress tracking.

โœจ Features

  • โšก Blazing Fast - Parallel async downloads (5-10x faster than traditional tools)
  • ๐ŸŽฏ Smart Filters - Download by media type (photos, videos, audio, documents)
  • ๐Ÿ“ Size Control - Filter by file size (min/max)
  • ๐Ÿ”„ Auto-Resume - Automatically skips already downloaded files
  • ๐Ÿ“Š Progress Bars - Real-time progress with download statistics
  • ๐Ÿ’พ Session Management - Secure login with saved sessions
  • ๐Ÿ›ก๏ธ Error Handling - Graceful error recovery and interruption handling
  • โš™๏ธ Configurable - Customize parallel downloads and output directories
  • ๐ŸŽจ User-Friendly - Beautiful CLI interface with colors and emojis

๐Ÿ“ฆ Installation

From PyPI (Recommended)

pip install tgdl

From Source

git clone https://github.com/kavidu-dilhara/tgdl.git
cd tgdl
pip install -e .

๐Ÿš€ Quick Start

1. Get API Credentials

Get your Telegram API credentials from https://my.telegram.org/apps

2. Login

tgdl login

Enter your API ID, API Hash, and phone number when prompted.

3. List Your Channels/Groups/Bots

# List all channels
tgdl channels

# List all groups
tgdl groups

# List all bot chats
tgdl bots

4. Download Media

# Download all media from a channel
tgdl download -c CHANNEL_ID

# Download only photos and videos
tgdl download -c CHANNEL_ID -p -v

# Download from a bot chat
tgdl download -b BOT_ID -d

# Download with file size limit
tgdl download -g GROUP_ID --max-size 100MB

# Download from a message link
tgdl download-link https://t.me/channel/123

๐Ÿ“– Usage

Commands

tgdl login

Login to Telegram and save session.

tgdl login

tgdl channels

List all channels you're a member of.

tgdl channels

tgdl groups

List all groups you're a member of.

tgdl groups

tgdl bots

List all bot chats.

tgdl bots

tgdl download

Download media from a channel, group, or bot chat with filters.

tgdl download [OPTIONS]

Options:
  -c, --channel INTEGER       Channel ID to download from
  -g, --group INTEGER         Group ID to download from
  -b, --bot INTEGER           Bot chat ID to download from
  -p, --photos               Download only photos
  -v, --videos               Download only videos
  -a, --audio                Download only audio files
  -d, --documents            Download only documents
  --max-size TEXT            Maximum file size (e.g., 100MB, 1GB)
  --min-size TEXT            Minimum file size (e.g., 1MB, 10KB)
  --limit INTEGER            Maximum number of files to download
  --concurrent INTEGER       Number of parallel downloads (default: 5)
  -o, --output TEXT          Output directory (default: downloads)
  -h, --help                 Show this message and exit

tgdl download-link

Download media from a single message link.

tgdl download-link LINK [OPTIONS]

Options:
  -p, --photos               Accept only photos
  -v, --videos               Accept only videos
  -a, --audio                Accept only audio files
  -d, --documents            Accept only documents
  --max-size TEXT            Maximum file size
  --min-size TEXT            Minimum file size
  -o, --output TEXT          Output directory
  -h, --help                 Show this message and exit

tgdl status

Check authentication status and configuration.

tgdl status

Shows:

  • Authentication status
  • User information (name, ID, username)
  • Config file locations
  • API credentials (masked)

tgdl logout

Logout from Telegram and remove session.

tgdl logout

This will:

  • Remove your local session file
  • Delete stored API credentials
  • Optionally clear download progress

tgdl --version

Show version information.

tgdl --version

๐Ÿ“ File Organization

Downloaded files are organized as follows:

downloads/
โ”œโ”€โ”€ entity_1234567890/          # Channel/Group ID
โ”‚   โ”œโ”€โ”€ file1.jpg
โ”‚   โ”œโ”€โ”€ file2.mp4
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ single_downloads/            # Files from download-link
    โ”œโ”€โ”€ video.mp4
    โ””โ”€โ”€ ...

โš™๏ธ Configuration

Configuration is stored in ~/.tgdl/:

  • config.json - API credentials and settings
  • tgdl.session - Telegram session (encrypted)
  • progress.json - Download progress tracker

๐ŸŽฏ Requirements

๐Ÿš€ Performance

  • 5-10x faster than traditional downloaders
  • Parallel downloads with configurable concurrency
  • Smart caching - skips already downloaded files
  • Optimized I/O - async operations throughout

Benchmarks

Files Sequential tgdl Speed Up
10 ~5 min ~1 min 5x
100 ~45 min ~8 min 5.6x
1000 ~7.5 hrs ~1.3 hrs 5.8x

Results vary based on internet speed and file sizes

๐Ÿ› ๏ธ Troubleshooting

Rate Limiting

If you get rate limited by Telegram, reduce concurrency:

tgdl download -c CHANNEL_ID --concurrent 2

Authentication Issues

If you have authentication problems:

# Check status
tgdl status

# Login again
tgdl login

Session Expired

Delete session and login again:

# On Linux/Mac
rm ~/.tgdl/tgdl.session

# On Windows
del %USERPROFILE%\.tgdl\tgdl.session

# Then login
tgdl login

๐ŸŽจ Screenshots

$ tgdl download -c 1234567890 -p -v

๐Ÿ“ฅ Download Settings
  Entity: Channel 1234567890
  Media types: photo, video
  Parallel downloads: 5
  Output: downloads

Found 123 already downloaded files, skipping...
Fetching messages from entity 1234567890...
Found 45 media files to download

Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 45/45 [02:15<00:00, 3.33file/s]

โœ“ Successfully downloaded 45 files!
Files saved to: downloads/entity_1234567890

๐ŸŽ‰ Download complete! 45 files downloaded.

๏ฟฝ Advanced Usage

Media Type Filters

Combine multiple media type filters:

# Photos and videos only
tgdl download -c 1234567890 -p -v

# Only documents
tgdl download -c 1234567890 -d

# Only audio files
tgdl download -c 1234567890 -a

File Size Filters

Control file sizes:

# Download files between 1MB and 100MB
tgdl download -c 1234567890 --min-size 1MB --max-size 100MB

# Only large files (>50MB)
tgdl download -c 1234567890 --min-size 50MB

# Only small files (<10MB)
tgdl download -c 1234567890 --max-size 10MB

Limit Number of Files

# Download only first 10 files
tgdl download -c 1234567890 --limit 10

# Download first 100 videos
tgdl download -c 1234567890 -v --limit 100

Custom Output Directory

# Save to custom directory
tgdl download -c 1234567890 -o /path/to/downloads

# Use relative path
tgdl download -c 1234567890 -o ./my_downloads

Performance Tuning

# Slow but safe (good for rate limits)
tgdl download -c 1234567890 --concurrent 2

# Balanced (default)
tgdl download -c 1234567890 --concurrent 5

# Fast (if you have good internet)
tgdl download -c 1234567890 --concurrent 10

๐Ÿ” Security & Privacy

  • API credentials stored securely in ~/.tgdl/config.json
  • Session file encrypted by Telethon
  • No data sent to third parties
  • All downloads happen directly from Telegram servers

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

โš ๏ธ Disclaimer

This tool is for personal use only. Please respect:

  • Telegram's Terms of Service
  • Copyright laws
  • Content creators' rights
  • Rate limits and server resources

๐Ÿ”— Links

๐Ÿ’ฌ Support

If you have questions or need help:

  • Open an issue on GitHub
  • Check existing issues for solutions

Made with โค๏ธ by kavidu-dilhara

Happy Downloading! ๐ŸŽ‰

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

tgdl-1.1.2.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tgdl-1.1.2-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file tgdl-1.1.2.tar.gz.

File metadata

  • Download URL: tgdl-1.1.2.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tgdl-1.1.2.tar.gz
Algorithm Hash digest
SHA256 84413953cee083cbb4b8c07e8eb52d1aaf6394385107f52eb97a0bdd20864191
MD5 6a029311be6999c49cd65c5b383f5039
BLAKE2b-256 51ee31ad7b0945d54527e35a480b33be752eaf4da87e7bc892190d6196bd2022

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgdl-1.1.2.tar.gz:

Publisher: release.yml on kavidu-dilhara/tgdl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgdl-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: tgdl-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tgdl-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ddd2e4c61181463859cb6b31e0565f92f3706d3020cd69b038219becea5d87eb
MD5 1690965edaf8e34522a03d2a4f7c7a9c
BLAKE2b-256 b08dcbf823c336e60b7b7c40a19f46aefa3f2103f6643bc915b22ba6adfae2fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgdl-1.1.2-py3-none-any.whl:

Publisher: release.yml on kavidu-dilhara/tgdl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page