Convert .torrent file to magnet link/uri

5.9k views Asked by At

If found a lot of similar questions, but they were all about python or other programming languages that I don't really understand.

My question is really simple: How do I convert a .torrent file into a magnet link/URI? Assuming that functions like Base32Encode() or GetSha1Hash() already exist in the program. It doesn't really have to be in javascript, something like "You have to base32 encode the first 80 bytes of the file, multiply it by 5 and create an sha-1 hash form it would be enough.

1

There are 1 answers

2
Blender On BEST ANSWER

The simplest magnet URI is just the hex-encoded info hash of the torrent:

magnet:?xt=urn:btih:{info_hash}

To compute the info hash of a torrent, you need to SHA1-sum the info dict of the torrent file as a string.