tdl/README.md

401 lines
9.6 KiB
Markdown
Raw Normal View History

2023-01-31 20:27:10 +08:00
# tdl
2022-09-05 20:04:10 +08:00
![](https://img.shields.io/github/go-mod/go-version/iyear/tdl?style=flat-square)
![](https://img.shields.io/github/license/iyear/tdl?style=flat-square)
2022-12-22 17:11:54 +08:00
![](https://img.shields.io/github/actions/workflow/status/iyear/tdl/master.yml?branch=master&style=flat-square)
2022-09-05 20:04:10 +08:00
![](https://img.shields.io/github/v/release/iyear/tdl?color=red&style=flat-square)
![](https://img.shields.io/github/downloads/iyear/tdl/total?style=flat-square)
2022-09-05 20:04:10 +08:00
2022-09-05 22:14:03 +08:00
📥 Telegram Downloader, but more than a downloader 🚀
2022-09-05 20:04:10 +08:00
2023-01-31 20:27:10 +08:00
## Contents
* [Features](#features)
* [Preview](#preview)
* [Install](#install)
* [Quick Start](#quick-start)
* [Usage](#usage)
* [Basic Configs](#basic-configs)
* [Login](#login)
* [Download](#download)
* [Upload](#upload)
* [Backup](#backup)
* [Chat Utilities](#chat-utilities)
* [Env](#env)
* [Data](#data)
* [Commands](#commands)
* [Best Practice](#best-practice)
* [FAQ](#faq)
2022-09-18 17:18:04 +08:00
2022-09-05 20:04:10 +08:00
## Features
- Single file start-up
- Low resource usage
2022-09-15 15:52:53 +08:00
- Take up all your bandwidth
2022-09-05 20:04:10 +08:00
- Faster than official clients
2022-09-15 15:52:53 +08:00
- Download files from (protected) chats
- Upload files to Telegram
2022-09-05 22:48:52 +08:00
## Preview
2022-09-15 15:52:53 +08:00
It reaches my proxy's speed limit, and the **speed depends on whether you are a premium**
2022-09-05 22:48:52 +08:00
![](img/preview.gif)
2022-09-12 21:42:39 +08:00
## Install
Go to [GitHub Releases](https://github.com/iyear/tdl/releases) to download the latest version
2022-10-08 15:43:58 +08:00
(optional) Use it everywhere:
2023-01-31 20:27:10 +08:00
```powershell
2022-11-23 08:39:05 +08:00
# Should run as root(Administrator)
2022-10-08 15:43:58 +08:00
# Linux & macOS
2022-11-23 08:39:05 +08:00
sudo mv tdl /usr/bin
2022-10-08 15:43:58 +08:00
# Windows (PowerShell)
Move-Item tdl.exe C:\Windows\System32
```
Install with a package manager:
```shell
# Scoop (Windows) https://scoop.sh/#/apps?s=2&d=1&o=true&p=1&q=telegram+downloader
scoop bucket add extras
scoop install telegram-downloader
```
2022-10-19 11:08:06 +08:00
## Quick Start
```shell
# login with existing official desktop clients (recommended)
2023-03-22 10:28:40 +08:00
tdl login -n quickstart
2022-11-23 20:03:21 +08:00
# if you set a local passcode
2023-03-22 10:28:40 +08:00
tdl login -n quickstart -p YOUR_PASSCODE
# specify custom path
tdl login -n quickstart -d /path/to/TelegramDesktop
2022-10-19 11:08:06 +08:00
# or login with phone & code
2023-03-22 10:28:40 +08:00
tdl login -n quickstart --code
2022-10-19 11:08:06 +08:00
tdl dl -n quickstart -u https://t.me/telegram/193
```
2022-09-05 20:04:10 +08:00
## Usage
2022-12-22 17:11:54 +08:00
- Get help
2022-09-26 00:18:42 +08:00
2022-09-05 20:04:10 +08:00
```shell
2022-09-17 10:05:02 +08:00
tdl -h
2022-09-26 00:18:42 +08:00
```
2022-12-22 17:11:54 +08:00
- Check the version
2022-09-17 10:05:02 +08:00
2022-09-26 00:18:42 +08:00
```shell
2022-09-05 20:04:10 +08:00
tdl version
2022-09-26 00:18:42 +08:00
```
2022-09-05 20:04:10 +08:00
2022-09-26 00:18:42 +08:00
### Basic Configs
> The following command documents will not write basic configs. Please add the basic configs you need.
2022-10-19 11:08:06 +08:00
Each namespace represents a Telegram account
2022-09-26 00:18:42 +08:00
You should set the namespace **when each command is executed**:
```shell
2022-09-20 11:04:48 +08:00
tdl -n iyear
# or
2022-09-26 00:18:42 +08:00
export TDL_NS=iyear # recommended
```
2022-12-22 17:11:54 +08:00
- (optional) Set the proxy. Only support socks now:
2022-09-20 11:04:48 +08:00
2022-09-26 00:18:42 +08:00
```shell
2022-09-15 15:52:53 +08:00
tdl --proxy socks5://localhost:1080
2022-09-20 11:04:48 +08:00
# or
2022-09-26 00:18:42 +08:00
export TDL_PROXY=socks5://localhost:1080 # recommended
```
2022-12-22 17:11:54 +08:00
- (optional) Set ntp server host. If is empty, use system time:
2022-09-05 20:04:10 +08:00
2022-09-26 00:18:42 +08:00
```shell
2022-09-21 20:59:45 +08:00
tdl --ntp pool.ntp.org
# or
2022-09-26 00:18:42 +08:00
export TDL_NTP=pool.ntp.org # recommended
```
### Login
> When you first use tdl, you need to login to get a Telegram session
2022-12-22 17:11:54 +08:00
- If you have [official desktop clients](https://desktop.telegram.org/) locally, you can import existing sessions.
2022-10-03 16:23:13 +08:00
This may reduce the risk of blocking, but is unproven:
2022-09-26 00:18:42 +08:00
```shell
2023-03-22 10:28:40 +08:00
tdl login
2022-11-23 20:03:21 +08:00
# if you set a local passcode
2023-03-22 10:28:40 +08:00
tdl login -p YOUR_PASSCODE
# specify custom path
tdl login -d /path/to/TelegramDesktop
2022-09-26 00:18:42 +08:00
```
2022-12-22 17:11:54 +08:00
- Login to Telegram with phone & code:
2022-09-26 00:18:42 +08:00
```shell
2023-03-22 10:28:40 +08:00
tdl login --code
2022-09-26 00:18:42 +08:00
```
### Download
> Please do not arbitrarily set too large `threads` and `size`.
>
> **The default value of options is consistent with official clients to reduce the risk of blocking.**
>
2022-09-30 22:55:09 +08:00
> If you need higher speed, set higher threads and size
>
2022-09-26 00:18:42 +08:00
> For details: https://github.com/iyear/tdl/issues/30
2022-12-22 17:11:54 +08:00
- Download (protected) chat files from message urls:
2022-09-26 00:18:42 +08:00
```shell
tdl dl -u https://t.me/tdl/1 -u https://t.me/tdl/2
```
2022-12-22 17:11:54 +08:00
- Download (protected) chat files from [official desktop client exported JSON](docs/desktop_export.md):
2022-09-21 20:59:45 +08:00
2022-09-26 00:18:42 +08:00
```shell
tdl dl -f result1.json -f result2.json
```
2022-12-22 17:11:54 +08:00
- You can combine sources:
2022-09-26 00:18:42 +08:00
```shell
2022-12-22 17:11:54 +08:00
tdl dl \
-u https://t.me/tdl/1 -u https://t.me/tdl/2 \
-f result1.json -f result2.json
2022-09-26 00:18:42 +08:00
```
2022-12-22 17:11:54 +08:00
- Download with 8 threads, 512KiB(MAX) part size, 4 concurrent tasks:
2022-09-26 00:18:42 +08:00
```shell
2022-09-30 22:55:09 +08:00
tdl dl -u https://t.me/tdl/1 -t 8 -s 524288 -l 4
2022-09-26 00:18:42 +08:00
```
2022-12-22 17:11:54 +08:00
- Download with real extension according to MIME type:
> **Note**
> If the file extension is not matched with the MIME type, tdl will rename the file with the correct extension.
>
> Side effect: like `.apk` file, it will be renamed to `.zip`.
```shell
tdl dl -u https://t.me/tdl/1 --rewrite-ext
```
- Skip the same files when downloading:
> **Note**
> IF: file name(without extension) and size is the same
```shell
tdl dl -u https://t.me/tdl/1 --skip-same
```
- Download files to custom directory:
```shell
tdl dl -u https://t.me/tdl/1 -d /path/to/dir
```
- Download files with custom order:
> **Note**
> Different order will affect resuming download
```shell
# download files in descending order(from newest to oldest)
tdl dl -f result.json --desc
# Default is ascending order
tdl dl -f result.json
```
2022-12-22 17:11:54 +08:00
- Download files with extension filters:
> **Note**
> The extension is only matched with the file name, not the MIME type. So it may not work as expected.
>
> Whitelist and blacklist can not be used at the same time.
```shell
# whitelist filter, only download files with `.jpg` `.png` extension
tdl dl -u https://t.me/tdl/1 -i jpg,png
# blacklist filter, download all files except `.mp4` `.flv` extension
tdl dl -u https://t.me/tdl/1 -e mp4,flv
```
- Download with custom file name template:
Please refer to [template guide](docs/template.md) for more details.
```shell
2022-12-22 17:11:54 +08:00
tdl dl -u https://t.me/tdl/1 \
--template "{{ .DialogID }}_{{ .MessageID }}_{{ .DownloadDate }}_{{ .FileName }}"
```
2022-12-22 17:11:54 +08:00
- Full example:
2022-09-26 00:18:42 +08:00
```shell
2022-12-22 17:11:54 +08:00
tdl dl --debug --ntp pool.ntp.org \
-n iyear --proxy socks5://localhost:1080 \
-u https://t.me/tdl/1 -u https://t.me/tdl/2 \
-f result1.json -f result2.json \
--rewrite-ext --skip-same -i jpg,png \
-d /path/to/dir --desc \
2022-12-22 17:11:54 +08:00
-t 8 -s 262144 -l 4
2022-09-26 00:18:42 +08:00
```
### Upload
> Same instructions and advanced options as **Download**
2022-12-22 17:11:54 +08:00
- Upload files to `Saved Messages`, exclude the specified file extensions:
2022-09-26 00:18:42 +08:00
```shell
tdl up -p /path/to/file -p /path/to/dir -e .so -e .tmp
```
2022-12-22 17:11:54 +08:00
- Upload with 8 threads, 512KiB(MAX) part size, 4 concurrent tasks:
2022-09-26 00:18:42 +08:00
```shell
2022-09-30 22:55:09 +08:00
tdl up -p /path/to/file -t 8 -s 524288 -l 4
2022-09-26 00:18:42 +08:00
```
2023-01-31 20:27:10 +08:00
- Upload to custom chat:
```shell
# chat input examples: `@iyear`, `iyear`, `123456789`(chat id), `https://t.me/iyear`, `+1 123456789`
# empty chat means `Saved Messages`
tdl up -p /path/to/file -c CHAT_INPUT
```
2022-12-22 17:11:54 +08:00
- Full example:
2022-09-26 00:18:42 +08:00
```shell
2022-12-22 17:11:54 +08:00
tdl up --debug --ntp pool.ntp.org \
-n iyear --proxy socks5://localhost:1080 \
-p /path/to/file -p /path/to/dir \
-e .so -e .tmp \
-t 8 -s 262144 -l 4
2023-01-31 20:27:10 +08:00
-c @iyear
2022-09-26 00:18:42 +08:00
```
### Backup
2022-09-15 15:52:53 +08:00
> Backup or recover your data, often used for migrating session to remote server
2022-09-17 15:46:22 +08:00
2022-12-22 17:11:54 +08:00
- Backup (Default: `tdl-backup-<time>.zip`):
2022-09-05 20:04:10 +08:00
2022-09-26 00:18:42 +08:00
```shell
tdl backup
# or specify the backup file path
tdl backup -d /path/to/backup.zip
```
2022-12-22 17:11:54 +08:00
- Recover:
2022-09-05 20:04:10 +08:00
2022-09-26 00:18:42 +08:00
```shell
tdl recover -f /path/to/backup.zip
```
2022-09-15 15:52:53 +08:00
2022-09-26 00:18:42 +08:00
### Chat Utilities
2022-09-15 15:52:53 +08:00
2022-09-26 00:18:42 +08:00
> Some useful utils
2022-12-22 17:11:54 +08:00
- List all your chats:
2022-09-26 00:18:42 +08:00
```shell
tdl chat ls
2022-09-05 20:04:10 +08:00
```
2022-12-22 17:11:54 +08:00
- Export minimal JSON for tdl download (NOT for backup):
2022-10-14 23:42:17 +08:00
```shell
# will export all media files in the chat.
# chat input examples: `@iyear`, `iyear`, `123456789`(chat id), `https://t.me/iyear`, `+1 123456789`
2023-01-31 20:27:10 +08:00
# export all messages
2022-10-14 23:42:17 +08:00
tdl chat export -c CHAT_INPUT
2023-03-22 10:28:40 +08:00
# export with specific timestamp range, default is start from 1970-01-01, end to now
tdl chat export -c CHAT_INPUT -i 1665700000,1665761624
# or (time is default type)
tdl chat export -c CHAT_INPUT -i 1665700000,1665761624 -T time
# export with specific message id range, default is start from 0, end to latest message
tdl chat export -c CHAT_INPUT -i 100,500 -T id
2022-11-04 12:57:23 +08:00
2023-03-22 10:28:40 +08:00
# export last N media files
tdl chat export -c CHAT_INPUT -i 100 -T last
2022-10-14 23:42:17 +08:00
# specify the output file path, default is `tdl-export.json`
tdl chat export -c CHAT_INPUT -o /path/to/output.json
```
2022-09-20 11:04:48 +08:00
## Env
Avoid typing the same flag values repeatedly every time by setting environment variables.
**Note: The values of all environment variables have a lower priority than flags.**
What flags mean: [flags](docs/command/tdl.md#options)
2022-12-22 17:11:54 +08:00
| NAME | FLAG |
|:------------:|:---------------:|
| TDL_NS | `-n/--ns` |
| TDL_PROXY | `--proxy` |
| TDL_DEBUG | `--debug` |
| TDL_SIZE | `-s/--size` |
| TDL_THREADS | `-t/--threads` |
| TDL_LIMIT | `-l/--limit` |
| TDL_NTP | `--ntp` |
| TDL_TEMPLATE | dl `--template` |
2022-09-20 11:04:48 +08:00
2022-09-05 20:04:10 +08:00
## Data
Your account information will be stored in the `~/.tdl` directory.
2023-01-31 20:27:10 +08:00
Log files will be stored in the `~/.tdl/log` directory.
2022-09-05 20:04:10 +08:00
## Commands
2022-09-26 00:18:42 +08:00
Go to [docs](docs/command/tdl.md) for full command docs.
2022-09-05 20:04:10 +08:00
2022-09-28 00:28:20 +08:00
## Best Practice
How to minimize the risk of blocking?
- Login with the official client session.
- Use the default download and upload options as possible. Do not set too large `threads` and `size`.
- Do not use the same account to login on multiple devices at the same time.
- Don't download or upload too many files at once.
- Become a Telegram premium user. 😅
2022-09-17 00:33:28 +08:00
2022-09-17 10:03:20 +08:00
## FAQ
2022-09-26 00:18:42 +08:00
2022-09-17 10:03:20 +08:00
**Q: Is this a form of abuse?**
2022-09-26 00:18:42 +08:00
A: No. The download and upload speed is limited by the server side. Since the speed of official clients usually does not
reach the account limit, this tool was developed to download files at the highest possible speed.
2022-09-17 10:03:20 +08:00
2022-09-17 13:15:11 +08:00
**Q: Will this result in a ban?**
2022-09-26 00:18:42 +08:00
A: I am not sure. All operations do not involve dangerous actions such as actively sending messages to other people. But
it's safer to use an unused account for download and upload operations.
2022-09-17 13:15:11 +08:00
2022-11-20 18:59:02 +08:00
**Q: No response after entering the command?**
A: Check if you need to use a proxy (use `proxy` flag); Check if your system's local time is correct (use `ntp` flag or calibrate system time)
If that doesn't work, run again with `debug` flag. Then file a new issue and paste your log in the issue.
2022-09-05 20:04:10 +08:00
## LICENSE
AGPL-3.0 License