Skip to content
Projects

botnick/telegram-media-downloader

View on GitHub

About

Self-hosted Telegram media downloader with a web dashboard. Download and back up photos, videos and files from Telegram channels, groups and DMs, including private ones. Docker, PWA, dedup, face clustering, NSFW review, cluster mode, Go engine.

Systems & Infrastructure

How these counts are measured

What you can do

  • Realtime monitor for channels, groups, forum topics and private chats, with per-chat media-type, sender and topic filters
  • Monitor that restarts itself after errors, with a per-minute watchdog
  • History backfill (pull older, catch up, rescan, optional date window) that resumes after a restart
  • t.me/ message links, Telegram Stories and self-destructing (TTL) media

Measured star growth

in 24h
0
in 7 days
+8
in 15 days
+13
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

Latest release MIT License Go 1.26 Docker image on ghcr.io CI status

Telegram Media Downloader

Self-hosted Telegram media downloader with a web dashboard.
Download and archive photos, videos, files, voice messages and Stories from Telegram channels, groups and chats
you belong to, with your own account. One Go binary or Docker image. No bot, no cloud.

Quick start • Features • Dashboard • FAQ • Website • ภาษาไทย • Docs

3.x is a native Go server. Node.js is gone: one tgdl-server binary (or the Docker image) runs everything. 2.x installs upgrade in place with the same image, port, data folder and logins, and since 3.4 the 2.x background features are back too: auto-forward, self-destructing media, disk rotation, Google Drive and Dropbox backups, seekbar previews, NSFW and face sidecars. See Upgrading from 2.x.

Library: every downloaded photo and video, grouped by date, with the chat list on the left

Why this tool?

Problem What it does
Bots only see chats they were added to, with file-size limits Signs in as your account over MTProto: if you can read it, it can save it
No easy way to archive a whole channel History backfill that survives restarts, plus a realtime monitor
The same video forwarded everywhere Skips duplicates before downloading, then confirms by SHA-256
Files scattered across devices Web dashboard and PWA on any browser in your network
Sharing a file with someone without an account Signed, expiring share links you can revoke
Copying new media to another chat or topic Auto-forward through a durable queue that survives restarts and respects FloodWaits
Keeping a copy somewhere else Backups to a local disk, S3, SFTP, FTP/FTPS, Google Drive or Dropbox, optionally encrypted

Quick start

You need a Telegram apiId and apiHash from my.telegram.org.

Docker (recommended)

mkdir telegram-media-downloader && cd telegram-media-downloader
mkdir -p data
curl -fsSLO https://raw.githubusercontent.com/botnick/telegram-media-downloader/main/docker-compose.yml
docker compose up -d

Set the first dashboard password from a private file containing one line (at least 8 characters), then delete the file:

docker compose exec -T -u node telegram-downloader tgdl-server setup --password-stdin < /path/to/password-file

Open http://localhost:3000 and:

  1. Sign in with that password.
  2. Settings → Telegram API: paste apiId and apiHash.
  3. Settings → Accounts → Add: phone and login code, or scan a QR code from the Telegram app; then the 2FA password if the account has one.
  4. Chats: turn on the monitor, start a backfill, or paste a t.me/ link.

The image is multi-arch (amd64, arm64). Synology users can start from docker-compose.synology.yml.

Native binary (no Docker)

Download tgdl-server-v<version>-<os>-<arch>.tar.gz for Linux, Windows or macOS from the latest release, then:

tar -xzf tgdl-server-v*-linux-amd64.tar.gz
TGDL_DATA_DIR=./data ./tgdl-server

On the same machine, http://localhost:3000 shows the setup form for the first password. Install ffmpeg for thumbnails and video previews.

On Windows, Scoop installs and updates it, keeping your data across updates (details):

scoop bucket add tgdl https://github.com/botnick/telegram-media-downloader
scoop install tgdl/tgdl-server

Prefer a git checkout? ./runner.sh (Windows: run_safe.bat) downloads and verifies the matching release for you. Details, systemd and reverse-proxy examples: Install and deploy.

Features

Downloading

  • Realtime monitor for channels, groups, forum topics and private chats, with per-chat media-type, sender and topic filters
  • Monitor that restarts itself after errors, with a per-minute watchdog
  • History backfill (pull older, catch up, rescan, optional date window) that resumes after a restart
  • t.me/ message links, Telegram Stories and self-destructing (TTL) media
  • Auto-forward new files to Saved Messages, channels, chats and forum topics, several destinations per chat, through a durable queue that survives restarts, waits out FloodWaits and never resends an uncertain delivery on its own
  • Direct forwarding without downloading, protected copies and custom captions
  • Several Telegram accounts; pin each chat to the account that reads it
  • SOCKS5, SOCKS4, HTTP and MTProxy proxies
  • Adaptive parallel downloads (scale between a minimum and maximum with the queue), FloodWait protection, retries and a live bandwidth limit
  • Rescue mode: keep only media whose source message was deleted
  • Optional folders per forum topic (Group/Topic/images), globally or per chat

Library

  • Duplicates skipped by Telegram media identity, confirmed by SHA-256, plus a duplicate finder with bulk delete
  • Gallery with thumbnails, search, pins, bulk delete and ZIP download
  • Video player with MP4 faststart and seekbar hover previews; signed, expiring share links
  • Separate tab for deleted or inaccessible chats; leave dead chats in bulk
  • Message archive (per chat): save the text of every message, read the chat offline as a conversation, search it and export to HTML or JSON
  • Import a collection downloaded earlier by another app: files are matched to their Telegram messages and never downloaded again
  • Installable PWA, dark and light theme, English, Thai, Indonesian and Simplified Chinese

Operations

  • One-click update from the dashboard (Docker + bundled watchtower), with a verified database snapshot first, or scheduled automatic updates
  • Backups to local disk, S3-compatible storage, SFTP, FTP/FTPS, Google Drive and Dropbox, with encrypted archives and offline restore
  • Archive locations: move older files to an external drive or NAS folder and keep them in the library, verified by SHA-256
  • Whole-app backup and restore in the dashboard: one encrypted file with the database, settings and Telegram accounts
  • Cluster mode: pair instances, browse each other's files, cross-peer duplicate sweep
  • Optional disk rotation (deletes the oldest downloads over a size cap), periodic integrity sweep, database and file verification, recovery tools
  • Processing history of every download attempt and forward (30 days)
  • Prometheus /metrics; FFMPEG_HWACCEL hardware decoding for thumbnails

Security

  • Fail-closed: nothing is reachable until a password is set
  • scrypt password hashes, HttpOnly + SameSite=Strict cookies revoked on the server, login limited to 10 attempts per 15 minutes
  • Read-only guest password; Telegram sessions encrypted at rest
  • CSP and security headers; TRUST_PROXY for reverse proxies

AI (optional): seekbar previews are built into the server. Face recognition and NSFW scanning run in the optional tgdl-faces and tgdl-nsfw containers (a commented tgdl-nsfw service is in the compose files). See AI: faces, NSFW and previews.

Dashboard

Chats: pick which channels and groups to monitor Chat details: monitoring, what to download, storage
Chats — monitor channels, groups and DMs; backfill history Chat details — what to download and storage, in one page
Download queue with live progress, speed and ETA Go-anywhere palette (Ctrl+K)
Queue — live progress, speed, ETA; pause, retry or cancel any file Ctrl+K — jump to any page, tool, setting or chat
Full-screen media viewer Tools: library health, backup and sync, system
Viewer — swipe / arrow keys, pin, share link, download Tools — duplicates, thumbnails, backups, cluster, maintenance

Library on a phone Viewer on a phone Queue on a phone Chats on a phone, light theme

The same dashboard on a phone, in dark or light theme. Screenshots use generated demo images and fictional chat names.

How it works

flowchart LR
    browser[Browser / PWA] <-- HTTP + WebSocket --> server[tgdl-server]
    server <-- MTProto via gotd --> telegram[(Telegram)]
    server --> queue[Durable queue]
    queue --> files[(downloads/)]
    server <--> db[(SQLite)]
    server -- thumbnails, previews --> ffmpeg[ffmpeg]
    server -. optional .-> sidecars[tgdl-faces / tgdl-nsfw]

tgdl-server is a single Go program. It serves the embedded dashboard, owns the SQLite database and the Telegram connections, and runs downloads, dedup, backups and maintenance. Downloads are written to a .part file and published atomically, so an interrupted transfer never leaves a half file in the library. More in Architecture.

Updating

  • In the dashboard (Docker): Settings → Maintenance → Install update.
  • Automatically (Docker): WATCHTOWER_HTTP_API_PERIODIC_POLLS=true in .env updates all containers on a schedule (default daily 04:00).
  • Docker, by hand: docker compose pull && docker compose up -d
  • Native: replace the binary, or git pull and restart ./runner.sh.

Migrations run automatically. Coming from 2.x: nothing to change, see Upgrading from 2.x.

Configuration

Settings live in the dashboard and are stored in SQLite. Environment variables cover start-up only:

Variable Default Purpose
TGDL_PORT 3000 Host port in docker-compose.yml
TGDL_DATA_DIR /app/data (Docker), ./data (launchers) Data folder (required for a bare binary)
TGDL_DOWNLOADS_DIR <data>/downloads Keep media on another disk
TRUST_PROXY 1 in Compose Reverse-proxy trust
TGDL_SECURE_COOKIES 0 Set 1 behind HTTPS
TGDL_BIND_HOST all interfaces Listen address, e.g. 127.0.0.1

Full list: Configuration.

data/
├── db.sqlite          # settings, catalog, jobs, sessions
├── secret.key         # BACK THIS UP: decrypts the Telegram sessions
├── sessions/native/   # encrypted Telegram logins
├── downloads/<chat>/  # your media
├── thumbs/            # generated thumbnails
├── seekbar/           # video preview sprites
└── backups/           # database snapshots (incl. pre-update)

FAQ

How do I download all media from a Telegram channel?

Add your Telegram account (Settings → Accounts), open Chats, pick the channel and start a backfill. Choose how many messages to read, or 0 for all of them. The queue shows each file with progress, speed and ETA. Turn on the realtime monitor for that chat to keep the archive current.

Can it download from private channels and groups?

Yes, if the Telegram account you sign in with is a member. The tool acts as that account over the Telegram user API (MTProto), so it reads what you can read in the Telegram app.

How is this different from a Telegram bot?

Bots use the Bot API, which limits file sizes and only sees chats the bot was added to. This tool logs in as your user account through MTProto, so it has no bot-style file-size cap and sees your own chats.

Is my Telegram session safe?

Sessions are encrypted at rest in data/sessions/, with the key in data/secret.key. Nothing is sent to a service run by this project. The dashboard fails closed: without a password nobody gets in. Put it behind HTTPS if you expose it, and back up secret.key. See SECURITY.md.

Will my account get banned?

It uses the normal user API like a Telegram app, but heavy automated downloading always carries some risk. Failed downloads retry with growing delays; keep parallel downloads and the bandwidth limit moderate, and avoid running many accounts from one IP. Telegram's FloodWait limits are respected automatically: short waits are slept through and long ones pause only that account. No tool can promise zero risk.

Does it run on a Raspberry Pi or a Synology NAS?

Yes. The Docker image is built for amd64 and arm64, and release binaries also cover 32-bit ARM (linux-arm). Synology has its own compose file. See Install and deploy.

Can I download Stories or single messages?

Yes. Look up a user's Stories by username and pick what to save, or paste t.me/... message links (channel, group, forum topic and private links).

Do I need Node.js?

No. Since 3.0 the server is a single Go binary. npm start and PM2 still work for old setups; they only call the launcher, which downloads that binary.

Where are the files stored, and can I back them up?

Under data/downloads/<chat>/, or TGDL_DOWNLOADS_DIR on another disk. Backups go to a local folder, S3-compatible storage (AWS, R2, B2, Wasabi, MinIO), SFTP, FTP/FTPS, Google Drive or Dropbox, with optional encryption and an offline restore command. Maintenance → Backup → Whole-app backup downloads the database, settings and Telegram accounts as one encrypted file and restores it from the dashboard. See Backup.

ภาษาไทย

Telegram Media Downloader คือโปรแกรมโหลดรูป วิดีโอ และไฟล์จากช่อง กลุ่ม และแชต Telegram ฟรีและโอเพนซอร์ส ติดตั้งบนเครื่องหรือ NAS ของคุณเองด้วย Docker หรือไฟล์ Go ไฟล์เดียว ล็อกอินด้วยบัญชี Telegram ของคุณ จึงโหลดจากช่องส่วนตัวที่เป็นสมาชิกได้ เฝ้าแชตแบบเรียลไทม์ ดึงข้อความย้อนหลังทั้งช่อง ข้ามไฟล์ซ้ำ และสำรองข้อมูลไป S3, Google Drive หรือ Dropbox ได้ ส่งต่อไฟล์ใหม่ไปหลายแชตหรือหลาย topic ผ่านคิวที่ไม่หายเมื่อรีสตาร์ท แยกโฟลเดอร์ตาม topic ได้ เก็บข้อความแชตไว้อ่านและค้นหาแบบออฟไลน์ และนำเข้าไฟล์เก่าที่เคยโหลดด้วยโปรแกรมอื่นโดยไม่ต้องโหลดซ้ำ หน้าเว็บจัดการมีภาษาไทย อ่านต่อที่หน้าเว็บภาษาไทย

Documentation

Page Contents
Install and deploy Docker, release binaries, systemd, reverse proxy, updating
Upgrading from 2.x What carries over, what changed, rolling back
Configuration Dashboard settings, environment variables, data folder
Features Everything 3.x does and what is still missing
Backup Local, S3, SFTP, FTP/FTPS, Google Drive, Dropbox, encryption, restore
Cluster mode Pairing several instances
Forward queue Auto-forward jobs, retries, FloodWait, restart recovery
Small hosts Raspberry Pi and other 1 GiB hosts, building the image with little memory
AI: faces, NSFW and previews Seekbar previews and the face and NSFW sidecars
API reference HTTP and WebSocket endpoints
Troubleshooting Common problems and fixes
Architecture How the server is built
Changelog Release notes

The docs are also published as a searchable site at botnick.github.io/telegram-media-downloader, and llms.txt gives AI assistants a curated index.

Contributing

make build   # core-service/tgdl-server
make test    # Go tests
make check   # gofmt, go vet, race tests

See CONTRIBUTING.md.

Acknowledgements

Thanks to Zacky Achmad (@zckyachmd) for the forwarding work in 3.5.0: the durable forward queue, FloodWait protection, forum topic routes, processing history and the Indonesian translation, and for the small-host build and Raspberry Pi guidance in 3.5.1.

Thanks to @eason102 for Safari and iOS playback of HEVC downloads and GPU seekbar previews with VA-API in 3.5.2.

Thanks to @sampotter123 for asking for QR-code sign-in (3.6.0), for the careful diagnosis of the chat-list failure fixed in 3.7.1, and for archive locations (3.8.0), forum-topic folders (3.9.0), the message archive (3.10.0) and importing an existing collection (3.11.0).

Thanks to @chengnas for the Simplified Chinese translation of the dashboard in 3.7.1.

License

MIT. Not affiliated with Telegram. Uses the MTProto user API via gotd.

Explore related projects

Loading…