Often see movies Friends are not unfamiliar with the BT seeds, but the BT seed file relative to the magnetic chain is not easy to store, and on the site to store BT files easy to cause copyright disputes, and the magnetic chain is relatively less risky.
Converting BT seeds to a smaller footprint and sharing a more convenient magnetic chain is a big benefit.
Today, let's see how to convert the seed into a magnetic link, the scheme is: Using Python's Bencode module, it is relatively simple to use.
To install this module first, install the command:
Pip Install Bencode
If PIP is not installed, go to the detailed Python Package manager pip installation
Actual combat code
After the installation is complete, let's look at the code:
System Environment: Linux
Python Environment: Python2.7
Please note that the Python version
bt2url.py
#! /usr/local/bin/python# @desc Python generates magnetic links via BT seeds # @date 2015/11/10# @author pythontab.comimport bencodeimport sysimport Hashlibimport base64import urllib# Get parameters torrentname = sys.argv[1] #读取种子文件torrent = open (Torrentname, ' RB '). Read () # Calculate meta Data metadata = bencode.bdecode (torrent) hashcontents = Bencode.bencode (metadata[' info ') Digest = HASHLIB.SHA1 ( hashcontents). Digest () B32hash = Base64.b32encode (Digest) #打印print ' magnet:?xt=urn:btih:%s '% B32hash
How do I use it?
Command:
Python bt2url.py test.torrent
Results:
Magnet:?xt=urn:btih:mwxfhxoge2umr7wbfzyejpm3lf2vihnh