Skip to content
Projekte

rfsbraz/telegram-downloader

Auf GitHub ansehen

Über uns

Self-hosted daemon that automatically downloads media from Telegram channels, groups and forum topics.

Produktivität und Automatisierung

So werden diese Zahlen gemessen

What you can do

  • Multi-Source - Channels, groups, supergroups, forum topics, private chats
  • Smart Filtering - By extension, file size, date range, filename patterns
  • Auto-Organization - Per-source folders, duplicate detection, conflict resolution, persistent download tracking
  • Daemon Mode - Runs continuously with configurable check intervals

Gemessener Sternzuwachs

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Verlauf wird gesammelt

Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.

README.md

Original

Telegram Media Downloader

CI Docker License: MIT Docker Pulls

A self-hosted daemon that automatically downloads media from Telegram channels, groups, and forum topics. Configure once, run forever.

Looking for a telegram-download-daemon alternative? See Moving from telegram-download-daemon for a settings map and a before and after docker-compose.yml.

Documentation | Quick Start | Examples

Why?

Telegram is great for sharing files, but manually downloading from multiple sources is tedious. This tool runs in the background and:

  • Downloads new files as they're posted
  • Filters by extension, size, date, or filename pattern
  • Organizes files into folders by source
  • Skips duplicates automatically
  • Tracks downloads persistently so files aren't re-downloaded after being moved or renamed
  • Sends notifications when downloads complete

Features

Feature Description
Multi-Source Channels, groups, supergroups, forum topics, private chats
Smart Filtering By extension, file size, date range, filename patterns
Auto-Organization Per-source folders, duplicate detection, conflict resolution, persistent download tracking
Daemon Mode Runs continuously with configurable check intervals
Notifications Discord webhooks, generic HTTP POST
Metrics Opt-in Prometheus /metrics endpoint
Docker Native Multi-arch images (amd64/arm64), health checks, non-root

Quick Start

Prerequisites

  • Docker and Docker Compose
  • Telegram API credentials from my.telegram.org/apps
  • Telegram account with access to the channels/groups you want to download from
Where to find the channel URL

Setup

mkdir telegram-downloader && cd telegram-downloader

cat > docker-compose.yml << 'EOF'
services:
  telegram-downloader:
    image: rfsbraz/telegram-downloader:latest
    restart: unless-stopped
    environment:
      - TDL_API_ID=YOUR_API_ID
      - TDL_API_HASH=YOUR_API_HASH
      - TDL_PHONE_NUMBER=+1234567890
      - TDL_DAEMON_ENABLED=true
      - TDL_DAEMON_CHECK_INTERVAL=300
      - TDL_SOURCES_0_URL=https://t.me/example_channel
    volumes:
      - ./downloads:/downloads
      - ./sessions:/app/.sessions
    stdin_open: true
    tty: true
EOF

docker compose run --rm telegram-downloader

On first run, you'll be prompted for the Telegram verification code sent to your phone. After authentication, restart with docker compose up -d for daemon mode.

Installing on Unraid? See Install on Unraid for the template and the first-run login steps.

Configuration

All configuration is done via environment variables with the TDL_ prefix. See the full configuration reference for all options.

Sources

# Public channel
- TDL_SOURCES_0_URL=https://t.me/channel_name

# Private channel/group (use the t.me/c/ link format)
- TDL_SOURCES_1_URL=https://t.me/c/1234567890/1

# Forum topic (chat_id/topic_id)
- TDL_SOURCES_2_URL=https://t.me/c/1234567890/123

Filters

# File extensions (comma-separated)
- TDL_SOURCES_0_FILTERS_EXTENSIONS=.pdf,.epub,.mobi

# Size limits
- TDL_SOURCES_0_FILTERS_MIN_SIZE=100KB
- TDL_SOURCES_0_FILTERS_MAX_SIZE=500MB

# Global defaults (apply to all sources)
- TDL_GLOBAL_FILTERS_EXTENSIONS=.pdf,.epub

# Compressed Telegram photos (opt-in, default off)
- TDL_GLOBAL_FILTERS_INCLUDE_PHOTOS=true

Dry run

Preview what a run would download without writing anything:

- TDL_DRY_RUN=true
- TDL_DAEMON_ENABLED=false

Use this with a single-shot run to check filters first. Nothing is downloaded, and the session directory, state.db, cursors, history, and the pending queue are left unchanged. The preview tracks planned files in memory so duplicates and name collisions match a real run. It scans from the current cursor only (pending retries are not included) and does not apply max_downloads_per_run, so every match is listed. If dry-run is left on in daemon mode, every check logs a warning.

Daemon Mode

- TDL_DAEMON_ENABLED=true
- TDL_DAEMON_CHECK_INTERVAL=300  # seconds between checks

Post-Download Hook

Run a command after each successful download - extract archives, convert formats, trigger library scans, move files to watch folders:

- TDL_POST_DOWNLOAD_HOOK=unrar x "{file}" "{dir}"
- TDL_POST_DOWNLOAD_HOOK_TIMEOUT=300  # seconds, default 300

Available placeholders: {file} (absolute path), {dir} (parent directory), {filename}, {extension}, {source} (source display name), {size} (bytes).

The command runs without a shell (filenames can't inject arguments) and a hook failure never marks the download as failed.

Scheduling & Bandwidth

Control when checks run and how fast downloads go - useful for metered connections or shared networks:

# Only run download checks inside these windows (24h, local time via TZ).
# Multiple windows and cross-midnight windows are supported.
- TDL_SCHEDULE_ACTIVE_HOURS=02:00-08:00,22:00-23:59

# Cap aggregate download speed across all concurrent downloads
- TDL_MAX_DOWNLOAD_SPEED=5MB

Outside active hours the daemon stays alive (health checks keep passing) but skips download checks. A download already in flight when a window closes is never interrupted. Both settings default to unrestricted.

Notifications

- TDL_NOTIFICATIONS_ENABLED=true
- TDL_NOTIFICATIONS_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...

Metrics

Off by default. When enabled, Prometheus can scrape /metrics on port 9184:

- TDL_METRICS_ENABLED=true
- TDL_METRICS_PORT=9184

See the metrics guide for the scrape config, the metric list, and a starter Grafana dashboard.

Docker Environment

# User/group ID for file permissions (arr-stack compatible)
- PUID=1000
- PGID=1000

# Timezone
- TZ=Europe/Lisbon

# Store all files in download_dir without per-channel subfolders
- TDL_FLAT_STRUCTURE=true

# Persistent download tracking (enabled by default)
# When enabled, files won't be re-downloaded after being moved/renamed
- TDL_TRACK_DOWNLOADS=true

Examples

Complete Docker Compose configurations for common use cases:

Example Description
ebook-forum.yml Download ebooks from forum topics
youtube-archiver.yml Archive YouTube mirror channels
news-aggregator.yml Aggregate media from news channels
personal-backup.yml Backup your saved messages

Docker Images

Available from Docker Hub and GitHub Container Registry:

# Docker Hub
docker pull rfsbraz/telegram-downloader:latest

# GitHub Container Registry
docker pull ghcr.io/rfsbraz/telegram-downloader:latest
Tag Description
latest Latest stable release
edge Latest main branch (may be unstable)
v1.2.3 Specific version
v1.2 Latest patch for minor version
v1 Latest minor for major version
sha-abc1234 Specific commit

Multi-arch: linux/amd64 and linux/arm64 (Raspberry Pi 4+, Apple Silicon, AWS Graviton).

Install on Unraid

This repository includes a Community Applications XML template at templates/telegram-downloader.xml. It is not listed in the Community Applications store yet. Install it as a user template.

Add the template

  1. Copy templates/telegram-downloader.xml to /boot/config/plugins/dockerMan/templates-user/telegram-downloader.xml on your Unraid server.
  2. Open the Docker tab and click Add Container.
  3. Select telegram-downloader from the Template dropdown.
  4. Set API ID, API Hash, and Phone Number from my.telegram.org/apps.
  5. Set at least one source URL (TDL_SOURCES_0_URL).
  6. Confirm the Downloads and Sessions host paths. The Sessions path also stores download state. Back it up.
  7. Click Apply.

If the container starts before a session file exists, stop it before the next step.

First-run authentication

Unraid's container console opens a new shell. It does not attach to the app's stdin, so you cannot enter the Telegram login code there.

Authenticate with a one-shot container that uses the same Sessions path and PUID/PGID as the template:

docker run --rm -it \
  -e PUID=99 \
  -e PGID=100 \
  -e TDL_API_ID=YOUR_API_ID \
  -e TDL_API_HASH=YOUR_API_HASH \
  -e TDL_PHONE_NUMBER=+1234567890 \
  -e TDL_DAEMON_ENABLED=false \
  -v /mnt/user/appdata/telegram-downloader:/app/.sessions \
  rfsbraz/telegram-downloader:latest

Enter the login code Telegram sends to your account. If two-factor authentication is enabled, enter that password too.

You can omit source URLs in this one-shot command. After login the process exits with an error that no sources are configured. That is expected. The session file is already saved in the Sessions path as telegram_downloader.session.

Start the template container after login completes. It reuses the session and runs in daemon mode.

If you later see AUTH_KEY_UNREGISTERED, delete telegram_downloader.session from the Sessions path, run the one-shot command again, then restart the container.

Troubleshooting

Error Solution
PEER_ID_INVALID The chat ID is invalid or you haven't joined the chat. Open it in Telegram first.
FloodWait X Rate limited by Telegram. The daemon waits automatically. Increase check interval if persistent.
AUTH_KEY_UNREGISTERED Session expired or revoked, at startup or mid-run. The daemon notifies once, marks the container unhealthy and waits instead of restarting. Delete ./sessions/telegram_downloader.session, re-authenticate, then restart.
Health check failing Check logs with docker compose logs -f

See the troubleshooting guide for more.

Development

git clone https://github.com/rfsbraz/telegram-downloader.git
cd telegram-downloader
pip install -r requirements.txt
make test          # all tests with coverage
make unit          # unit tests only
make integration   # integration tests only
make build         # build Docker image
make run           # build + docker compose up

See CONTRIBUTING.md for full development guidelines.

License

MIT - see LICENSE for details.

Acknowledgments

☕ Support

If you find this useful and want to support development, you can buy me a coffee - no pressure at all, just a nice way to say thanks.

Ähnliche Projekte entdecken

Wird geladen…