iyear / tdl

📥 A Telegram toolkit written in Golang
https://docs.iyear.me/tdl
GNU Affero General Public License v3.0
4.46k stars 442 forks source link

[Bug] Invalid argument during downloads #733

Closed wolffparkinson closed 3 weeks ago

wolffparkinson commented 1 month ago

Describe the bug

Throws invalid argument while downloading a file.

Command :

tdl dl -f tdl-export.json --skip-same --template "[{{ .MessageID }}] {{ replace .FileName `:` `_` }}" --reconnect-timeout 0 --continue
Error: callback:
    github.com/gotd/td/telegram.(*Client).Run.func3
        github.com/gotd/td@v0.108.0/telegram/connect.go:151
  - iter:
    github.com/iyear/tdl/core/downloader.(*Downloader).Download
        github.com/iyear/tdl/core@v0.0.0-00010101000000-000000000000/downloader/downloader.go:59
  - create file:
    github.com/iyear/tdl/app/dl.(*iter).process
        github.com/iyear/tdl/app/dl/iter.go:212
  - open downloads/[757] 3_AOE_:Sclara_and_its_pathology_LIMBUS_AND_OCCULAR_ROUTES_OF_DRUG.tmp: invalid argument

To Reproduce

Private channel.

Expected behavior

Should download the file

Version

Version: 0.17.4 Commit: c63abd1 Date: 2024-09-08T15:56:41Z

go1.21.13 linux/amd64

Which OS are you running tdl on?

Linux

Additional context

No response

iyear commented 1 month ago

I guess this filename might be invalid on Linux. Try changing the template flag to {{ .MessageID }} to verify.

wolffparkinson commented 1 month ago

Colons : are not a valid symbol in linux file name. Changing the template flag to {{ .MessageID }} works. But {{ replace .FileName:`_ }}` should work.

wolffparkinson commented 3 weeks ago

After trying a few combinations, looks like have to add forward slash (\) before each backtick (`) in the template to escape the backticks, else linux terminal will misbehave.

Working template :

--template "[{{ .MessageID }}] {{ replace .FileName \`/\` \`_\` \`:\` \`_\` \`*\` \`_\` \`?\` \`\` \`<\` \`_\` \`>\` \`_\` \`|\` \`_\` \`\\\` \`_\` }}"