Question

I was searching how to pass an argument in torrent_info() function during the use of magnet links in libtorrent. Especially my target is to analyze peers and pieces. With the use of .torrent file the process is obvious throw other given paradigms in this site:

e = lt.bdecode(open("torrent.torrent", 'rb').read())
info = lt.torrent_info(e)

But what happens with the magnet links?

params = {
    'save_path': 'C:\Python26',
    'storage_mode': lt.storage_mode_t(2),
    'paused': False,
    'auto_managed': True,
    'duplicate_is_error': True}
link = "magnet:?........."

handle = lt.add_magnet_uri(ses, link, params)

Which variable is equivalent to "e" of the .torrent process in magnet links case in order to be able to use torrent_info function properly?

Was it helpful?

Solution

Adding a magnet link gives you a torrent handle, from which you will be able to get torrent infos (once the metadata has been fetched - it will throw otherwise).

Unlike torrent files, where the metadata is already here, magnet links require the metadata to be retrieved from the network as a starter, and that can take some time.

I'm more used to the C++ library, but well - to have it demo at the dirtiest, you can do something in the line of:

handle = lt.add_magnet_uri(ses, link, params)
while (not handle.has_metadata()):
   time.sleep(.1)
info = handle.get_torrent_info()

... then, you can read all about it here ;) http://www.rasterbar.com/products/libtorrent/manual.html#torrent-info

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top