from libtorrent as lt
info = lt.torrent_info(open('example.torrent','rb').read())
info.info_hash()
Run Code Online (Sandbox Code Playgroud)
这不会得到哈希,而是得到了对象 <libtorrent.big_number object at ...... >
我该怎么办?
现有的答案为您提供了所需的一切......但是这里有一些代码可以使它明确:
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)
Run Code Online (Sandbox Code Playgroud)
编辑:实际上,这是错的 - torrent_info()应该传递torrent文件的长度及其内容.修订(工作)版本:
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)
Run Code Online (Sandbox Code Playgroud)