Search code examples
pythonlibtorrentmagnet-uri

why magnet generated by libtorrent are invalid?


I try to get magnet links from a torrent file, according to libtorrent doc with this code :

info = lt.torrent_info(t) # t is a torrent file
return(lt.make_magnet_uri(info))

It returns a link :

magnet:?xt=urn:btih:YC5BHBHYDFYZOJRMD5BYGA2QRRXVRGAM&dn=BTshare.ogv

But this link doesn't work. (Note there is no problem with the torrent file).

So, I tried to retrieve magnet link of this torrent with transmission. It turns out that the result is different :

magnet:?xt=urn:btih:c0ba1384f8197197262c1f438303508c6f58980c&dn=BTshare.ogv

So I think there is a problem with the way I use python-libtorrent to get magnet link. Does anyone has a working example?

Regards.


Solution

  • The original magnet link format had the info-hash be base32 encoded, for space. At one point we (libtorrent and utorrent) decided it would be better to use hex (base16 encoded) for simplicity. This was probably around 2009 or 2010 iirc. However, in order to make the transition smooth, we supported reading both base32 and base16 style links (it's easy to tell the difference), but still generating base32 for backwards compatibility.

    libtorrent switched over to generating base16 magnet links in early 2013 (libtorrent 1.0).

    Chances are that you are using a very old version of libtorrent.