In practice, if Python is used to convert BT seeds into magnetic links, friends who often watch movies must be familiar with BT seeds. However, BT seed files are not easy to store than magnetic links, in addition, storing BT files on websites may cause copyright disputes, while magnetic chains are relatively less risky.
The conversion of BT seeds into smaller space is quite advantageous for sharing more convenient magnetic chains.
Today, let's take a look at how to convert seeds into magnetic links. the solution is to use python's bencode module to make it easier to use.
First, install this module. the installation command is as follows:
pip install bencode
If pip is not installed, go to "details python package manager pip installation"
Actual code
After the installation is complete, let's look at the code:
System environment: Linux
Python Environment: Python2.7
Note the python version
Bt2url. py
#! /Usr/local/bin/python # @ desc python generates a magnetic link through the BT seed # @ date 2015/11/10 # @ author pythontab. comimport bencodeimport sysimport hashlibimport base64import urllib # obtain the parameter torrentName = sys. argv [1] # read the seed file torrent = open (torrent name, '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 to use it?
Command:
python bt2url.py test.torrent
Result:
magnet:?xt=urn:btih:MWXFHXOGE2UMR7WBFZYEJPM3LF2VIHNH