Practice Python to convert BT seeds into magnetic links

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

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.