All Projects → JohnDoee → magnet2torrent

JohnDoee / magnet2torrent

Licence: MIT license
Turn a bittorrent magnet link into a .torrent file

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to magnet2torrent

torrent-spider
基于DHT的p2p网络资源爬虫
Stars: ✭ 65 (+44.44%)
Mutual labels:  bittorrent, magnet-link
Magnet Uri
Parse a magnet URI and return an object of keys/values
Stars: ✭ 183 (+306.67%)
Mutual labels:  bittorrent, magnet-link
torrent-hound
Search torrents from multiple websites via the CLI
Stars: ✭ 28 (-37.78%)
Mutual labels:  bittorrent, magnet-link
Bt Btt
磁力網站U3C3介紹以及域名更新
Stars: ✭ 261 (+480%)
Mutual labels:  bittorrent, magnet-link
Torrent
Full-featured BitTorrent client package and utilities
Stars: ✭ 4,138 (+9095.56%)
Mutual labels:  bittorrent, magnet-link
Aria2.sh
Aria2 一键安装管理脚本 增强版
Stars: ✭ 1,276 (+2735.56%)
Mutual labels:  bittorrent, magnet-link
Aria2 Pro Docker
Aria2 Pro | A perfect Aria2 Docker image | 更好用的 Aria2 Docker 容器镜像
Stars: ✭ 802 (+1682.22%)
Mutual labels:  bittorrent, magnet-link
Bt
BitTorrent library and client with DHT, magnet links, encryption and more
Stars: ✭ 2,011 (+4368.89%)
Mutual labels:  bittorrent, magnet-link
Dht
dht is used by anacrolix/torrent, and is intended for use as a library in other projects both torrent related and otherwise
Stars: ✭ 184 (+308.89%)
Mutual labels:  bittorrent
Newnode
NewNode decentralized Content Distribution Network
Stars: ✭ 223 (+395.56%)
Mutual labels:  bittorrent
Torrent Discovery
Discover BitTorrent and WebTorrent peers
Stars: ✭ 177 (+293.33%)
Mutual labels:  bittorrent
Magnetissimo
Web application that indexes all popular torrent sites, and saves it to the local database.
Stars: ✭ 2,551 (+5568.89%)
Mutual labels:  bittorrent
Luminance
Stars: ✭ 173 (+284.44%)
Mutual labels:  bittorrent
Biglybt Android
BiglyBT for Android, torrent client and remote control app
Stars: ✭ 180 (+300%)
Mutual labels:  bittorrent
Tv Overlord
TV Overlord — Download and manage tv shows:
Stars: ✭ 242 (+437.78%)
Mutual labels:  bittorrent
Dottorrent Gui
An advanced GUI torrent file creator with batch functionality, powered by PyQt and dottorrent
Stars: ✭ 175 (+288.89%)
Mutual labels:  bittorrent
trystero
🤝 Serverless WebRTC matchmaking for painless P2P — Make any site multiplayer in a few lines — Use BitTorrent, IPFS, or Firebase
Stars: ✭ 512 (+1037.78%)
Mutual labels:  bittorrent
Ipfilter
Keeps your preferred Bit Torrent client blocklist up to date to support your privacy and security
Stars: ✭ 241 (+435.56%)
Mutual labels:  bittorrent
Fastcast
🌊 Stream peer-to-peer audio and video content
Stars: ✭ 202 (+348.89%)
Mutual labels:  bittorrent
Autotorrent
Matches torrents with files and gets them seeded
Stars: ✭ 200 (+344.44%)
Mutual labels:  bittorrent

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

# try to fetch a torrent from the running server
# The response is json encoded and contains either the torrent or an error about it
curl "http://127.0.0.1:18667/?apikey=secretkey&magnet=magnet%3A%3Fxt%3Durn%3Abtih%3Ae2467cbf021192c241367b892230dc1e05c0580e%26dn%3Dubuntu-19.10-desktop-amd64.iso%26tr%3Dhttps%253A%252F%252Ftorrent.ubuntu.com%252Fannounce%26tr%3Dhttps%253A%252F%252Fipv6.torrent.ubuntu.com%252Fannounce"
# it will return {"status": "success", "filename": "ubuntu-19.10-desktop-amd64.iso.torrent", "torrent_data": "... base64 encoded torrent data ..."}

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)

Attacks on DHT

There are a number of attacks against Bittorrent DHT going on permanently. They have a variety of goals like trying to find new content on the DHT or just disrupt its operation.

One specific affects magnet2torrent, the "i am the peer for this" and then give back zero peers or just itself. This attack kinda short circuits the attempt to find a torrent. It mostly happen with low-peer torrents and when only the DHT got peers so it will be a bit uncommon.

The question I'm trying to answer here is "why can deluge/qbittorrent/picotorret etc. find a torrent when this library cannot". And that's probably why, libtorrent-rasterbar is smarter about it.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].