3
votes

I'm working to create a file sharing platform for open source software in Python.

The issue I'm hitting is how would I generate a magnet link (for storing in a database) from a directory? For example, I want to share dir /home/SHAREME. I know libtorrent has bindings for Python but no mention of creating a Magnet URI directly.

In addition, is it possible to "encode" Web Seeds into a Magnet URI? (http://www.rasterbar.com/products/libtorrent/manual.html#http-seeding)

I may be explaining this the wrong way but the use case is: 1. Call a function to create a Torrent Magnet URI for a folder 2. Insert the Magnet URI into a Database 3. Clients GET from DB and use Magnet URI to start downloading, using Web Seed

2

2 Answers

2
votes

There's no method exposed to create a magnet URI directly because such a link would be unusable!

Magnet links are hash identifiers that allow clients to retrieve a torrent file from the BitTorrent DHT network. However, they can only do so if there's at least one other client online (and with DHT enabled) that's downloading or seeding that torrent. If you generated a torrent within your application and generated a magnet link from that directly, nobody would ever have that torrent file, so it wouldn't be downloadable.

Long story short: Magnet links only really work for torrents that are created and seeded on a peer-to-peer basis. If you want to use a web seed, you'll need to offer the full torrent file for download by users.

1
votes

There is a approach for python3:

pip install magneturi

import magneturi
magneturi.from_torrent_file('xx.torrent')