Bittorrent statistics..

amp_god 06.01.04 02:21

Hakee .torrent tiedostosta tarpeellisia tietoja.. mm. tiedoston koon, trackerin, seedien ja peerien määrän...

 Tekstiversio  Arvo: 2 (3 ääntä)  Äänestä: +  -
[code]
<table border="1" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td nowrap>.torrent file</td>
    <td nowrap>Name</td>
    <td nowrap>Size</td>
    <td nowrap>Seeds</td>
    <td nowrap>Peers</td>
    <td nowrap>Hash</td>
    <td nowrap>Announce</td>
    <td nowrap>Tracker</td>
  </tr>
<?php
### Settings... ###
$path = "/pub/torrents"; #Kansio mistä etsitään .torrent päätteisiä tiedostoja...
$max_cache_file_age = "3600"; #(1h)
###/Settings... ###
$time_alku=explode(" ", microtime());
$time_alku=$time_alku[0] + $time_alku[1];
set_time_limit(900);
ini_set(register_globals, "On");
function torrent_nfo($torrent) {
  global $max_cache_file_age;
  require_once("bencode.php");
  $bencode = new BEncodeLib();
  $file = fopen($torrent, "r");
  $stream = fread($file, filesize($torrent));
  fclose($file);
  $torrent = $bencode->bdecode($stream);
  $torrent[hash] = sha1($bencode->bencode($torrent[info]));
  $temp = tiedosto_loppu($torrent[announce]);
  $torrent[tracker] = ereg_replace($temp, "", $torrent[announce]);
  ## Tracker status... ##
  $tracker = "$torrent[tracker]" . "scrape";
  $tracker_md5 = md5($tracker);
  $cache_age = time() - @filemtime("/tmp/cache/$tracker_md5");
  if(file_exists("/tmp/cache/$tracker_md5") && $cache_age < $max_cache_file_age) {
    $open = fopen("/tmp/cache/$tracker_md5", "r");
    $scrape = fread($open, filesize("/tmp/cache/$tracker_md5"));
    $scrape = gzuncompress($scrape);
    fclose($open);
  }
  if(file_exists("/tmp/cache/$tracker_md5") && $cache_age > $max_cache_file_age) {
    $scrape = file_get_contents("$tracker");
    if(strlen($scrape) > 10) {
      $save = fopen("/tmp/cache/$tracker_md5", "w");
      fwrite($save, gzcompress($scrape));
      fclose($save);
    }
  }
  if(!file_exists("/tmp/cache/$tracker_md5")) {
    $scrape = file_get_contents("$tracker");
    if(strlen($scrape) > 10) {
      $save = fopen("/tmp/cache/$tracker_md5", "w");
      fwrite($save, gzcompress($scrape));
      fclose($save);
    }
  }
  $info = $bencode->bdecode($scrape);
  $torrent[seeds] = $info['files'][hex2bin($torrent[hash])]['complete'];
  $torrent[peers] = $info['files'][hex2bin($torrent[hash])]['incomplete'];
  ##/Tracker status... ##
  return $torrent;
}
function tiedosto_loppu($tiedosto) {
  $tiedosto = explode("/", $tiedosto);
  $tiedosto_pit = sizeof($tiedosto); $tiedosto_pit--;
  $tiedosto = $tiedosto[$tiedosto_pit];
  return($tiedosto);
}
function tiedosto_paate($tiedosto) {
  $tiedosto = explode(".", $tiedosto);
  $tiedosto_pit = sizeof($tiedosto); $tiedosto_pit--;
  $tiedosto = $tiedosto[$tiedosto_pit];
  return($tiedosto);
}
function hex2bin($hex)
{
        $result = '';
        for ($i = 0; $i < strlen($hex); $i += 2)
                $result .= chr(hexdec(substr($hex,$i,2)));
        return $result;
}
$files = shell_exec("find $path | grep -i torrent");
$files = explode("\n", $files);
natcasesort($files);
foreach($files as $file) {
  if(is_file($file) && filesize($file) > 0 && strtolower(tiedosto_paate($file)) == "torrent") {
    $torrent = torrent_nfo($file);
    $file_end = tiedosto_loppu($file);
    print("<tr><td nowrap>$file_end</td><td nowrap>" . $torrent[info][name] . "</td><td nowrap>" . $torrent[info][length] . "</td><td nowrap>" . $torrent[seeds] . "</td><td nowrap>" . $torrent[peers] . "</td><td nowrap>" . $torrent[hash] . "</td><td nowrap>" . $torrent[announce] . "</td><td nowrap>" . $torrent[tracker] . "</td></tr>\n");
  }
}
$time_loppu=explode(" ", microtime());
$time_loppu=$time_loppu[0] + $time_loppu[1];
$time = round($time_loppu - $time_alku, 2);
print("</table>\n<b>Processtime $time secs..");
?>
[/code]
Scripti vaatii toimiakseen uudehkon php:n + siihen gz tuen & http://www.rpguru.com/downloads/bencode_php.zip paketista bencode.php:n.. (bencode by Animesuki) + että kansio /tmp/cache on olemassa ja siihen kirjoitusoikeus
 

Ceron 11:41 9.1.04 
Toimiiko MBnetissä?
amp_god 18:52 11.1.04 
En mene takuuseen.. saattaa toimia tai sitten ei... luulen vaan ettei toimi kun MBNetissä on Safe Mode päällä...
eph 17:27 22.1.04 
Eipähän toimi minulla ainakaan.. Ulostaa pitkän rivin koodia pelkästään ennen <td> rivejä.
rottis 17:39 23.2.04 
juu safe mode pääl...
rottis 17:39 23.2.04 
siis mbnetis joten ei toimi :( ...