Decode .torrent files
Motivation
Yesterday I tried Tribler, which is a next generation torrent client. Its novelty is that it is decentralized, thus it doesn’t need trackers at all.
I noticed that Tribler contacts other clients to collect .torrent files that are stored locally. This way every client becomes a small “tracker”. I got curious to see what those .torrent files are. How to decode them?
Solution
.torrent files have a so-called bencode format. At effbot I found a simple decoder in Python that I extended a little bit. My version can be found here (and it’s part of my jabbapylib library now).
Usage
./bdecode.py ubuntu.torrent
Output:
{ 'announce': 'http://torrent.ubuntu.com:6969/announce',
'announce-list': [ ['http://torrent.ubuntu.com:6969/announce'],
['http://ipv6.torrent.ubuntu.com:6969/announce']],
'comment': 'Ubuntu CD releases.ubuntu.com',
'creation date': 1318500053,
'info': { 'length': 731164672,
'name': 'ubuntu-11.10-desktop-amd64.iso',
'piece length': 524288}}
ubuntu-11.10-desktop-amd64.iso
697.3 MB
As you can see, information about pieces is omitted. If you need that too, use the variable torrent.long_torrent.
Comments (0)
Trackbacks (0)
Leave a comment
Trackback