Question

We are doing a site wherein you are allowed to edit the trackers of a torrent file.

We are currently searching about the SEEDS and PEERS of a TRACKER.

We are confused how it worked. Is there somebody that knows how to show the SEEDS and PEERS of a torrent file in PHP?

Just like in the TORRENTEDITOR.COM, we've seen a code for it like this, but we don't understand how it works please help us.

    // global $seedsandpeers;
    if ($seedsandpeers === TRUE){
    if (!empty($array["announce-list"])){
        $announce = $array["announce-list"];
    // Possibly HtTp://
        $announce = strtolower($announce);
    if (substr($announce, 0, 7) === "http://"){
        if ((substr_count($announce, "/announce")) == 1){
            $scrape = str_replace('/announce', '/scrape', $announce);
            $httpget = "?info_hash=";
            $binsha1 = pack("H*", $infohash);
            $binsha1s = addslashes($binsha1);
            $fullurl = "$scrape$httpget$binsha1";
            $httpurl = pathurlencode($fullurl);
    sapeerconnect($httpurl, $binsha1s, $torrentsize);
    }  else {
$error = '<BR><label style="font-family:timesnewroman;font-size:12px;">Bad Tracker enter code hereURL for scraping (Maybe trackerless torrent).<br>' ;
echo $error;
}
}
else {
$error = '<BR><label style="font-family:timesnewroman;font-size:12px;">Bad Tracker URL for scraping (Maybe trackerless torrent).<br>';
echo $error;
}
}
}
Was it helpful?

Solution

So i've researched a bit, and it looks like you can decode a .torrent file :$

<?php
include 'functions.php';

$torrent_data = bdec(file_get_contents('test.torrent'));

$info=strtolower(sha1(benc($torrent_data['info'])));
$scrape=str_replace('announce','scrape',$torrent_data['announce']);
$sources=bdec(@file_get_contents($scrape.'?info_hash='.urlencode(hex2bin($info))));

$c=count($torrent_data['info']['files']);
echo '<h2>Files</h2>';

$files=array();
if($c > 1)
{
    for ($i = 0; $i < $c; $i++) $files[]=$torrent_data['info']['files'][$i]['path']['1'];
    sort($files);
    foreach($files as $file) echo $file."<br>";
}
else echo $torrent_data['info']['name']."<br>";

$seeds = $sources['files'][hex2bin($info)]['complete'];
$leechs = $sources['files'][hex2bin($info)]['incomplete'];
$downloads = $sources['files'][hex2bin($info)]['downloaded'];

echo '<h2>Sources</h2>'.
    '<b>Seeds:</b> '.$seeds.'<br/>'.
    '<b>Leechs:</b> '.$leechs.'<br/>' .
    '<b>Downloads:</b> '.$downloads.'<br/>';
?>

To use this code you first need to include a file with the benc, bdec and hex2bin functions. You can get these functions from Here

I have prepared a testcase, which can be found Here

Hope this helped.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top