Torrent_info () and magnetic link links in python bindings libtorrent

I was looking for how to pass an argument to the torrent_info () function while using magnetic links in libtorrent. Especially my goal is to analyze peers and pieces. Using a .torrent file, the process obviously throws other given paradigms on this site:

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

But what happens to magnetic 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 the "e" of the .torrent process in the case of magnetic links in order to be able to use the torrent_info function correctly?

+3
source share
1 answer

Adding a link to the magnet gives you a torrent descriptor from which you can get information about torrents (after the metadata is extracted - otherwise it will be different).

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

I'm more used to the C ++ library, but it's good - to have the demo in the dirtiest form, you can do something on the line:

 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

+6
source

Source: https://habr.com/ru/post/1483027/


All Articles