from libtorrent as lt
info = lt.torrent_info(open('example.torrent','rb').read())
info.info_hash()
This doesn't get the hash, instead I get the object <libtorrent.big_number object at ...... >
What should I do?
from libtorrent as lt
info = lt.torrent_info(open('example.torrent','rb').read())
info.info_hash()
This doesn't get the hash, instead I get the object <libtorrent.big_number object at ...... >
What should I do?
The existing answers give you everything you need ... but here's some 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: Actually, that's wrong - torrent_info()
should be passed the length of the torrent file as well as its content. 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)
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 the bytes and you have your hash.