In this third part of the tutorial (Parts I & II here), our goal is to show some information about our torrents and users. We’ll go through a bunch of tips and snippets that any developer may find useful while developing a torrent site, such as some util functions to display relative times, friendly sizes and a tree with files and folders.
A look at files tables
xbt_files, the table which contains records for all tracked torrents, gives us access to some information we’ll need to show on our torrent details page:
- • info_hash - Info hash of the torrent
- • leechers/seeders - Explains itself. Number of current leechers/seeders
- • completed - Number of times this torrent has been 100% downloaded by a peer
- • mtime - Last time this torrent has been updated as Unix timestamp
- • ctime - Time this torrent has been added to the tracker as Unix timestamp
- • flags - When this value is set to 1, XBTT will stop tracking the torrent and delete its record (we won’t need it here)
Our ideal details page will display those values in a cool box or table. The nicest way to display those time values is using a function that shows them as a relative time string. You may want to use this snippet at Snipplr.
The xbt_files_users table stores a torrent-user map for each torrent entry with information on peer activity.
- • fid - torrent ID
- • uid - user ID
- • active - whether this activity is still going on
- • announced - Number of announces
- • completed - Number of 100% complete transfers
- • downloaded/left/uploaded - Downloaded, left, uploaded bytes
- • mtime - Last update time
What we’ve just seen is all data related to peer activity. As well as this kind of stuff, we may want to display .torrent files details, just like any other torrent site does (just see the Details tab on any Minonova torrent). We’re going to look at some code to get this data and display it in a friendly way.
Getting .torrent metadata
In the previous part we’ve seen how to open a .torrent file and have access to bencoded values through File_Bittorrent2. The following code snippets will make use of this library.
First of all, we have to locate the .torrent file we want to open. If we have stored them using torrent IDs as filenames (as we’ve done in part 2), opening the file is as easy as those lines:
To display sizes we will use this handy function:
Now we’re ready to show the stuff we need:
echo $info[‘info_hash’] ?>
Total size <?php echo mksize($info[’size’]) ?> in <?php echo count($info[‘files’]) ?> files ### Torrent files tree
In order to display the files contained in our torrent, we’re going to output a file-tree including directories. As we have noticed, $info[‘files’] is an array containing all the files in the torrent. They are stored as paths, for example “directory/file1.txt”, “directory/file2.txt”, and so on, so, in order to build a tree, we need to separate directories from filenames and put them in a multidimensional array first. This is done by the following code.
$ret = array(); foreach ($files as $k => $v)
// build parent structure
$parent = &$ret;
foreach ($parts as $part)
$parent = &$parent[$part];
$parent[$leaf] = $v;
This function will loop through each file, split directories from filenames and organize them in a new array, which we can now display in a barebones HTML tree using a recursive function. Of course you will have to customize it using HTML/CSS or whatever and maybe add an appropriate icon before each file based on its extension; I’ll leave that to your creativity. Comments should be self-explanatory.
function outputTree($files, $indent=0)
foreach($files as $k=>$v)
$entry=isset($v[‘filename’]) ? $v[‘filename’] : $k;
elseif(is_array($v) && ((‘filename’,$v) && (’size’,$v)))
// normal node
// leaf node, i.e. a file
// we could output a folder icon here
// we could output an appropriate icon
// based on file extension here
echo “2. ”
echo $entry; // output folder name or filename
// if it’s not a folder, show file size
echo ” (“.mksize($size).”)”;
if(is_array($v) && $is_folder)
Some user data
Now that we are done with torrent data, there is nothing left to show
but some user details in profiles.
We need to fetch data from xbt_users, which contains trivial stuff like downloaded and uploaded bytes.
An important thing to show is the user ratio, which can be calculated by simply dividing uploaded by downloaded.
if($dl0 || $ul0)
return ‘-’; return $ratio=round($ul/$dl, 2);
This time we have looked at the structure of some XBTT tables which store information about tracker and torrent data. Also, we’ve fetched metadata from .torrent files and shown some snippets to output them in a nice and friendly way. I hope this helps out someone in speeding up development of new custom made torrent sites. Stay tuned for the following parts of the guide!
I always wondered how they tracked me =/
TBH there are quite enough new trackers being set up by 15 year old wannabe-sceners, making the scene unstable, insecure and way to high-profile. Leave making trackers to those that KNOW how to do it, instead of putting out the tools for the world to see. If we want the scene to stay alive we need to protect it, and I believe this article is doing nothing but damage to an already fragile community.
@LOKI: Impossible. This is just a series of tips and snippets for those who *already know* what they are doing and don’t want to spend too much time searching for (non existing) information about XBTT and other stuff.
lol LOKI if you are referring to the “proper” ’scene’ you are incorrect as every torrent site makes the scene insecure. If you mean the torrent ’scene’ then they dont make the scene insecure as they will just be the sites taken down rather than the people who know what they are doing
@HANGMAN & DUCKIE
Good points and duly taken.
ROTFL @ JJ … u r such a douche ..posting email in public is goin to get u banned on bmtv waffles t-d hd-bits and bhd …
lol @ LOKI’s comment … yea i too think that there are too many trackers released per day …. not many survive but still :facepalm: people make trackers just for fun ..
you think i use the same email… duh
Yeah, I tried to set one up for personal use before following similar steps, just could never get the thing working.
Part 4 has been published in the source site.Integrate it here?
Trackback :: How to Create a Tracker, Part 3: Torrent amp; User Details | THE … « Site Super Tracker
[…] Today found this great post, here is a quick excerpt : In this third part of the tutorial, our goal is to show some information about our torrents and users. We’ll go through a bunch of tips and snippets that any developer may find useful while developing a torrent site. Read the rest of this great post Here […]