Turn a bittorrent magnet links into a .torrent file.
Project description
Magnet2Torrent
Pure python project to turn a magnet link into a .torrent file. The goal is to do it as fast as possible.
Getting Started
Installing
pip install magnet2torrent
Usage
Download an ubuntu iso torrent.
magnet2torrent fetch "magnet:?xt=urn:btih:e2467cbf021192c241367b892230dc1e05c0580e&dn=ubuntu-19.10-desktop-amd64.iso&tr=https%3A%2F%2Ftorrent.ubuntu.com%2Fannounce&tr=https%3A%2F%2Fipv6.torrent.ubuntu.com%2Fannounce"
Run it as an HTTP server.
magnet2torrent serve
Run it as an HTTP server with lots of features enabled.
magnet2torrent --use-dht --dht-state-file dht.state --torrent-cache-folder torcache serve --apikey secretkey
Use from python
import asyncio
from magnet2torrent import Magnet2Torrent, FailedToFetchException
async def fetch_that_torrent():
m2t = Magnet2Torrent("magnet:?xt=urn:btih:e2467cbf021192c241367b892230dc1e05c0580e&dn=ubuntu-19.10-desktop-amd64.iso&tr=https%3A%2F%2Ftorrent.ubuntu.com%2Fannounce&tr=https%3A%2F%2Fipv6.torrent.ubuntu.com%2Fannounce")
try:
filename, torrent_data = await m2t.retrieve_torrent()
except FailedToFetchException:
print("Failed")
asyncio.run(fetch_that_torrent())
If you want to use DHT to retrieve, you will have to bootstrap and run it.
import asyncio
import os
from magnet2torrent import Magnet2Torrent, FailedToFetchException, settings
DHT_STATE_FILE = "/tmp/dht.state"
async def start_dht():
if os.path.exists(DHT_STATE_FILE):
dht_server = DHTServer.load_state(DHT_STATE_FILE)
await dht_server.listen(settings.DHT_PORT)
else:
dht_server = DHTServer()
await dht_server.listen(settings.DHT_PORT)
await dht_server.bootstrap(settings.DHT_BOOTSTRAP_NODES)
return dht_server
async def fetch_that_torrent(dht_server):
m2t = Magnet2Torrent("magnet:?xt=urn:btih:e2467cbf021192c241367b892230dc1e05c0580e&dn=ubuntu-19.10-desktop-amd64.iso", dht_server=dht_server)
try:
filename, torrent_data = await m2t.retrieve_torrent()
except FailedToFetchException:
print("Failed")
dht_server = asyncio.run(start_dht())
asyncio.run(fetch_that_torrent(dht_server))
dht_server.save_state(DHT_STATE_FILE)
License
This project is licensed under the MIT License - see the LICENSE.md file for details
The DHT part is forked from bmueller/kademlia - its license can be found in the dht folder or in the original project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
magnet2torrent-1.1.1.tar.gz
(21.7 kB
view hashes)
Built Distribution
Close
Hashes for magnet2torrent-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2bdc96d48308fd13a7fdfa190402cde0eaf8694a0099e4687e960b4a66abe3a |
|
MD5 | 390d126077c5f89101576f5ec9434b14 |
|
BLAKE2b-256 | aa3a0f81ea87b11e3ff7d9d8bb0fb008a5717d91d653e5bd45a3d451cd025b60 |