anacrolix / torrent

Full-featured BitTorrent client package and utilities
Mozilla Public License 2.0
5.58k stars 630 forks source link

fix: can not download invalid utf8 named torrent #915

Closed evrins closed 8 months ago

evrins commented 8 months ago

running on macOS sonoma 14.4 with M2 pro 

I found some magnet with invalid utf8 name fail to download with this library. but meanwhile qbitorrent handle it well. Maybe we should use BestName function in metainfo.Info and BestPath function in metainfo.FileInfo which may return human readable name in utf8 to successfully download this kind torrent.

before this patch invalid torrent will produce error message like this.

(base) ➜  Downloads torrent download 'magnet:?xt=urn:btih:0a5e2cbebf846baffd106bc01855bec11f6bd4e9'
361µs: getting torrent info for "infohash:0a5e2cbebf846baffd106bc01855bec11f6bd4e9"
9.145690083s: downloading "仙剑奇侠传三1080P": 0 B/72 GB, 0/4262 pieces completed (0 partial): 0 B/s
...
45.145761083s: downloading "仙剑奇侠传三1080P": 0 B/72 GB, 0/4262 pieces completed (0 partial): 0 B/s
[2024-03-18 09:52:15 +0800 ERR main client github.com/anacrolix/torrent peer.go:713]
  *torrent.PeerConn 0x1400129a008: writing received chunk 2047: open ?ɽ?????????1080P/?ɽ?????????01.mkv: no such file or directory

after this patch this torrent is successfully downloaded as 仙剑奇侠传三1080P

 torrent download 'magnet:?xt=urn:btih:0a5e2cbebf846baffd106bc01855bec11f6bd4e9'
49.792µs: getting torrent info for "infohash:0a5e2cbebf846baffd106bc01855bec11f6bd4e9"
5m6.973484417s: downloading "仙剑奇侠传三1080P": 0 B/72 GB, 0/4262 pieces completed (0 partial): 0 B/s
...
5m36.973856542s: downloading "仙剑奇侠传三1080P": 131 kB/72 GB, 0/4262 pieces completed (3 partial): 44 kB/s
5m39.974298875s: downloading "仙剑奇侠传三1080P": 524 kB/72 GB, 0/4262 pieces completed (4 partial): 131 kB/s
anacrolix commented 8 months ago

You might find this interesting https://github.com/BiglySoftware/BiglyBT/issues/1274