Skip to content

Commit

Permalink
chore(dl): takeout session is no longer enabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Apr 24, 2023
1 parent df1b092 commit 7607898
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ tdl dl -f result.json --desc
tdl dl -f result.json
```

- Download files with [takeout session](https://arabic-telethon.readthedocs.io/en/stable/extra/examples/telegram-client.html#exporting-messages):

> **Note**
> If you plan to download a lot of media, you may prefer to do this within a takeout session. Takeout sessions let you export data from your account with lower flood wait limits.
```shell
tdl dl -u https://t.me/tdl/1 --takeout
```

- Download files with extension filters:

> **Note**
Expand Down
10 changes: 10 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ tdl dl -f result.json --desc
tdl dl -f result.json
```

- 使用 [takeout session](https://arabic-telethon.readthedocs.io/en/stable/extra/examples/telegram-client.html#exporting-messages) 下载文件:

> **Note**
> If you plan to download a lot of media, you may prefer to do this within a takeout session. Takeout sessions let you export data from your account with lower flood wait limits.
> 如果你想下载大量的媒体文件,推荐在 takeout session 下进行。Takeout session 可以让你以更低的接口限制导出你的账户数据。
```shell
tdl dl -u https://t.me/tdl/1 --takeout
```

- 使用扩展名过滤器下载文件:

> **Note**
Expand Down
2 changes: 2 additions & 0 deletions app/dl/dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Options struct {
Include []string
Exclude []string
Desc bool
Takeout bool
PoolSize int64

// resume opts
Expand Down Expand Up @@ -113,6 +114,7 @@ func Run(ctx context.Context, opts *Options) error {
PartSize: viper.GetInt(consts.FlagPartSize),
Threads: viper.GetInt(consts.FlagThreads),
Iter: iter,
Takeout: opts.Takeout,
}
limit := viper.GetInt(consts.FlagLimit)

Expand Down
1 change: 1 addition & 0 deletions cmd/dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewDownload() *cobra.Command {

cmd.Flags().Int64Var(&opts.PoolSize, "pool", 3, "specify the size of the DC pool")
cmd.Flags().BoolVar(&opts.Desc, "desc", false, "download files from the newest to the oldest ones (may affect resume download)")
cmd.Flags().BoolVar(&opts.Takeout, "takeout", false, "takeout sessions let you export data from your account with lower flood wait limits.")

// resume flags, if both false then ask user
cmd.Flags().BoolVar(&opts.Continue, _continue, false, "continue the last download directly")
Expand Down
1 change: 1 addition & 0 deletions docs/command/tdl_download.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tdl download [flags]
--restart restart the last download directly
--rewrite-ext rewrite file extension according to file header MIME
--skip-same skip files with the same name(without extension) and size
--takeout takeout sessions let you export data from your account with lower flood wait limits.
--template string download file name template (default "{{ .DialogID }}_{{ .MessageID }}_{{ replace .FileName `/` `_` `\\` `_` `:` `_` `*` `_` `?` `_` `<` `_` `>` `_` `|` `_` ` ` `_` }}")
-u, --url strings telegram message links
```
Expand Down
10 changes: 9 additions & 1 deletion pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Downloader struct {
iter Iter
dir string
rewriteExt, skipSame bool
takeout bool
}

type Options struct {
Expand All @@ -42,6 +43,7 @@ type Options struct {
PartSize int
Threads int
Iter Iter
Takeout bool
}

func New(opts *Options) *Downloader {
Expand All @@ -54,6 +56,7 @@ func New(opts *Options) *Downloader {
dir: opts.Dir,
rewriteExt: opts.RewriteExt,
skipSame: opts.SkipSame,
takeout: opts.Takeout,
}
}

Expand Down Expand Up @@ -141,8 +144,13 @@ func (d *Downloader) download(ctx context.Context, item *Item) error {
return err
}

client := d.pool.Client(item.DC)
if d.takeout {
client = d.pool.Takeout(item.DC)
}

_, err = downloader.NewDownloader().WithPartSize(d.partSize).
Download(d.pool.Takeout(item.DC), item.InputFileLoc).
Download(client, item.InputFileLoc).
WithThreads(d.bestThreads(item.Size)).
Parallel(ctx, newWriteAt(f, tracker, d.partSize))
if err := f.Close(); err != nil {
Expand Down

0 comments on commit 7607898

Please sign in to comment.