


Practical Python implements conversion of BT seeds into magnet links
Friends who often watch movies must be familiar with BT seeds, but BT seed files are inconvenient to store compared to magnet links, and storing BT files on a website can easily cause copyright disputes, while magnet links are relatively less risky.
Converting BT seeds to magnet links that take up less space and are more convenient for sharing has great benefits.
Today we will take a look at how to convert seeds into magnet links. The solution is: use python’s bencode module, which is relatively simple to use.
First of all, you need to install this module. The installation command:
pip install bencode
If pip is not installed , please move to "Detailed explanation of python package manager pip installation"
Actual code
After the installation is completed, let's take a look at the code:
System environment: Linux
Python environment: Python2.7
Please pay attention to the python version
bt2url.py
#! /usr/local/bin/python # @desc python通过BT种子生成磁力链接 # @date 2015/11/10 # @author pythontab.com import bencode import sys import hashlib import base64 import urllib #获取参数 torrentName = sys.argv[1] #读取种子文件 torrent = open(torrentName, 'rb').read() #计算meta数据 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?
Command:
python bt2url.py test.torrent
Result:
magnet:?xt=urn:btih:MWXFHXOGE2UMR7WBFZYEJPM3LF2VIHNH

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Using python in Linux terminal...

Fastapi ...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
