torrent_info() and magnet links in libtorrent python bindings

安稳与你 提交于 2019-12-04 14:06:59

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/10251305/torrent-info-and-magnet-links-in-libtorrent-python-bindings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!