Practical python to convert BT seeds to magnetic links

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.