How use libtorrent for python to get info_hash
libtorrent, python
Solution
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)
Problem
``` 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?