How to use libtorrent for python to get info_hash

from libtorrent as lt info = lt.torrent_info(open('example.torrent','rb').read()) info.info_hash() 

This does not get a hash, instead I get an object <libtorrent.big_number object at ...... >

What should I do?

+4
source share
3 answers

The existing answers give you everything you need ... but there is code to make it explicit:

 import libtorrent as lt info = lt.torrent_info(open('example.torrent','rb').read()) info_hash = info.info_hash() hexadecimal = str(info_hash) integer = int(hexadecimal, 16) 

EDIT : this is actually not true - torrent_info() should pass the length of the torrent file and its contents. Revised (working) version:

 import libtorrent as lt torrent = open('example.torrent','rb').read() info = lt.torrent_info(torrent, len(torrent)) info_hash = info.info_hash() hexadecimal = str(info_hash) integer = int(hexadecimal, 16) 
+7
source

According to http://www.rasterbar.com/products/libtorrent/manual.html#torrent-info

 info_hash() returns the 20-bytes sha1-hash for the info-section of the torrent file. For more information on the sha1_hash, see the [big_number] class. 

So http://www.rasterbar.com/products/libtorrent/manual.html#big-number

Just iterate over bytes and you have a hash.

0
source

Just call str(info.info_hash()) .

Edit: str is actually wrong. But what is the correct way to write a hex string?

-2
source

All Articles