Reputation: 65
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.
Upvotes: 0
Views: 678
Reputation: 65
Even if I'm surprised to see libtorrent is outdated on debian jessie, i figured out the problem thanks to your answers. Tanks!
Here is the code now, needs to be improved :
info = lt.torrent_info(t)
b32m = (lt.make_magnet_uri(info))
mhash, dn = b32m.split('btih:')[1].split('&')
mhex = binascii.hexlify(base64.b32decode(mhash)).decode('ascii')
mgt = "magnet:?xt=urn:btih:{0}&{1}".format(mhex,dn)
return(mgt)
Upvotes: 1
Reputation: 11245
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.
Upvotes: 2
Reputation: 2268
If your question is "does anyone has a working example?", then there are a lot of working examples. Previous related question on this very site:
Given a .torrent file how do I generate a magnet link in python?
The link that works and the link that your code created only differ in the hash content YC5BHBHYDFYZOJRMD5BYGA2QRRXVRGAM
vs c0ba1384f8197197262c1f438303508c6f58980c
so yes, you guessed it right, there's something with the use of your lib to extract the hash value. (I failed to see in your link how to use Python wrapper around the C interface they documented). If you're not forced to use libtorrent you can try many other libs out there.
Upvotes: 1