Skip to content

Dr-Wade/telegram-archiver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Archiver

A Python script to archive all media from a Telegram group, including groups that restrict forwarding and downloading.

How it works

The script uses Telethon, a Python MTProto client that authenticates as a user account and communicates directly with the Telegram API. Because it operates at the protocol level, it can download any media your account can see — regardless of the UI-level forward/download restriction set by group admins.

Requirements

  • Python 3.8+
  • A Telegram account
  • Telegram API credentials (free, see setup below)

Setup

1. Get API credentials

  1. Go to https://my.telegram.org/apps
  2. Log in and create an application (any name/platform works)
  3. Note your API ID and API Hash

2. Install dependencies

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

3. Configure credentials

Copy .env.example to .env and fill in your values: pip

cp .env.example .env

Or export them directly:

export TG_API_ID=12345678
export TG_API_HASH=abcdef1234567890abcdef1234567890

Usage

python archive.py <group> [options]

Positional argument

Argument Description
group Group title, username (e.g. mygroupname), or numeric ID

Options

Flag Default Description
-o / --output ./archive Base output directory
--session archiver Telethon session file name
--min-id Only download messages with ID ≥ this
--max-id Only download messages with ID ≤ this
--dry-run List what would be downloaded without writing
--list-chats List all accessible groups/channels and exit
--api-id $TG_API_ID Telegram API ID
--api-hash $TG_API_HASH Telegram API Hash

Examples

# List all your groups to find the right one
python archive.py --list-chats

# Archive a group by name
python archive.py "My Group Name"

# Archive a group by username
python archive.py mygroupname

# Archive a group by numeric ID
python archive.py 1234567890

# Dry run first
python archive.py "My Group Name" --dry-run

# Custom output directory
python archive.py "My Group Name" -o /mnt/nas/backups

# Archive a specific message range
python archive.py "My Group Name" --min-id 1000 --max-id 2000

First run / Authentication

On the first run, Telethon will prompt you to log in:

Please enter your phone (or bot token): +1...
Please enter the code you received: 12345

A .session file is created locally so subsequent runs connect automatically.

Output structure

Files are saved under <output>/<group name>/:

archive/
└── My Group Name/
    ├── 20240101_120000_42_photo.jpg
    ├── 20240101_120500_43_document.pdf
    └── 20240102_083000_44_video.mp4

Each filename is prefixed with <YYYYMMDD_HHMMSS>_<msg_id>_ to avoid collisions. Re-running is safe — already-downloaded files are skipped automatically.

License

MIT — see LICENSE.

About

A Python script to archive all media from a Telegram group, including groups that restrict forwarding and downloading

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages