After using TorrentSpy on Windows for a while, I wanted a Mac version to do some of the same functions. TorrentSpy’s main feature is that it allows you to see the current number of users on a .torrent file in real-time. I was curious how it worked, so with a little traffic capturing with Ethereal, I was able to see that TorrentSpy was contacting the tracker listed inside the .torrent file at a specific address that was similar to the actual web address of the tracker. This special address, I figured, must hand real-time data back to TorrentSpy. After a minute or two of wandering around on Google (have I mentioned yet how much I love Google?), I came up with the protocol to be followed for transforming torrent announce URLs into “scrape” URLs on a Yahoo groups post. With this information, I started doing some coding in PHP to see what I could come up with.
The next problem presented was that of decoding a .torrent file so the information could be pulled out of it. A great open source project called TorrentParse came to the rescue here, as it provides PHP code for encoding and decoding BitTorrent metainfo files. As I would find out a short while later, these libraries are also pivotal in decoding the real-time information retrieved from the tracker server.
The code I wrote has only a small few parts. The first handles the uploading of a torrent file and checks to make sure it is of the required file type. The next partdecodes the given .torrent file with TorrentParse and extracts the announce URL (the address that the BitTorrent client notifies to show the new seed on the tracker). I wrote a small function called makescrape() that transforms the announce URL into a scrape URL per Bram’s post, linked to above. Upon requesting this new scrape URL, you are returned a BitTorrent-encoded chunk of data containing the real-time information about the torrent. Run that through TorrentParse’s decode function, and pull out the data you want to display.
I would post a demo of the code, but I’m afraid it would be automated and/or abused. However you’re free to download the code and try it out. It still needs some work, especially in handling and managing uploads, but it all works well enough to display basic real-time torrent information. It’s not exactly the Mac version I had in mind from the start, but it could be adapted to a Mac OS X widget with a little work. Get the code here. Enjoy.