.Torrent File Statistics

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Scam Warning
Locked
zDarkO
Registered User
Posts: 7
Joined: Sat Oct 24, 2009 11:19 am

.Torrent File Statistics

Post by zDarkO »

Hi there,

I have been looking all over the internet and on phpBB.com - I have found some .torrent mods for phpBB 3.0.x however they all become abandoned and never finished.

I was just wondering if there was actually a finished 3.0.x mod that allows the anonymous upload of .torrent files to the board and statistics of that .torrent file are automatically checked and the "seed", "leach" information from that .torrent file (from outside tracker) are put where the replys and views information is within each category for each post.

Also if possible the ability for this "seed", "leach" information to replace the "replys", "views" information depending of if the post has a .torrent file uploaded with it.

Regards,
zDark.
zDarkO
Registered User
Posts: 7
Joined: Sat Oct 24, 2009 11:19 am

Re: .Torrent File Statistics

Post by zDarkO »

What I really need is a torrent parsing script, that automatically parses the .torrent files uploaded within the post and then finds seeder and leach information through the first tracker that the torrent is listed on and then parses that information to the board.

Eg: Category ------------------------------------- Seeders -------- Leachers -------- Replies -------- Views
--- New Post - With Attachment (.torrent) --- 21 -------------- 34 ----------------2 ---------------- 101
are595
Registered User
Posts: 7
Joined: Mon Oct 12, 2009 4:03 pm

Re: .Torrent File Statistics

Post by are595 »

Well, after some searches I found this. Its not what you're looking for, but it will give you a start. I will try to put some work into this too.
zDarkO
Registered User
Posts: 7
Joined: Sat Oct 24, 2009 11:19 am

Re: .Torrent File Statistics

Post by zDarkO »

Awesome find, thank you so much!
And I would greatly appreciate your help with this.

Regards,
zDark.
are595
Registered User
Posts: 7
Joined: Mon Oct 12, 2009 4:03 pm

Re: .Torrent File Statistics

Post by are595 »

alright, well to start off, here is a little class I wrote to handle torrent files:

Code: Select all

<?php
//created by are595 at the phpbb.net forums, please don't remove this
//bdecode and bencode functions found at http://stackoverflow.com/questions/167206/php-module-for-reading-torrent-files
class torrent {
    var $file_name;
    var $seeders;
    var $leechers;
    var $downloads;
    var $info_hash; //important, used to identify the torrent.
    var $info=Array(); //info actually stored in the file
    
    function torrent($file) {
        if(!is_string($file)) {
            throw new Exception('File name must be string.');
        }
        
        $content=file_get_contents($file); //get torrent file contents
        $content_d = bdecode($content); //decode torrent file contents
        
        if(empty($content_d)) {
            exit('Something is wrong with the torrent. BDecode failed.');
        }
        
        $this->file_name=$file;
        $this->info_hash=$info_hash = sha1(bencode($content_d['info']), true);
        unset($content_d['info']['pieces']); //remove unnessasry data, takes up a lot of space
        
        foreach($content_d as $k=>$v) { //loop through and assign the info the the array
            if(is_array($v)&&$k!='announce-list') {
                foreach($v as $k2=>$v2) {
                    $this->info[$k2]=$v2;
                }
            } else {
                $this->info[$k]=$v;
            }
        }
    }
    
    function scrape($tries=-1) { //finds the torrent info (seeders, leechers, downloads)
        if($tries==-1) {
            $url=$this->info['announce'];
        } else {
            if(!isset($this->info['announce-list'])||!isset($this->info['announce-list'][$tries])) {
                $url=$this->info['announce'];
            } else {
                $url=$this->info['announce-list'][$tries][0];
            }
        }
        $loc=strrpos($url, '/');
        $scrape_url=substr($url, 0, $loc) . '/scrape?info_hash=' . urlencode($this->info_hash);
        $response='';
        
        if(function_exists('file_get_contents')) { //recomended you use file_get_contents as it has a timeout, fopen does not and will try to connect for 60 seconds
            $context = stream_context_create(array(
                'http' => array(
                    'timeout' => 1      // Timeout in seconds
                )
            ));
            @$response=file_get_contents($scrape_url, 0, $context); //get url contents with timeout
            }
        if(empty($response)||$response=='d5:filesdee') { //if no response or response it not valid
            $tries++;
            if(isset($this->info['announce-list'])&&isset($this->info['announce-list'][$tries])) {
                if($tries<5) { //set maximum number of tries here
                    $this->scrape($tries);
                }
            } else {
                //die('Connection timed out. This could be due to several problems:<br>1. Invalid tracker/the tracker is down.<br>2. The torrent is not registered with the tracker.');
            }
        return;
        }
        $this->parse_scrape($response);
    }
    
    function parse_scrape($t) {
        $response=bdecode($t);
    
        $this->info_hash=array_keys($response['files']);
        $this->info_hash=$this->info_hash[0];
    
        $main=$response['files'][$this->info_hash];
    
        $this->seeders=$main['complete'];
        $this->leechers=$main['incomplete'];
        $this->downloads=$main['downloaded'];
    
        unset($main);
        unset($response);
    }
}


/*start bdecode and bencode functions*/
function bdecode($str) {
    $pos = 0;
    return bdecode_r($str, $pos);
}

function bdecode_r($str, &$pos) {
    $strlen = strlen($str);
    if (($pos < 0) || ($pos >= $strlen)) {
            return null;
    }
    else if ($str{$pos} == 'i') {
            $pos++;
            $numlen = strspn($str, '-0123456789', $pos);
            $spos = $pos;
            $pos += $numlen;
            if (($pos >= $strlen) || ($str{$pos} != 'e')) {
                    return null;
            }
            else {
                    $pos++;
                    return intval(substr($str, $spos, $numlen));
            }
    }
    else if ($str{$pos} == 'd') {
            $pos++;
            $ret = array();
            while ($pos < $strlen) {
                    if ($str{$pos} == 'e') {
                            $pos++;
                            return $ret;
                    }
                    else {
                            $key = bdecode_r($str, $pos);
                            if ($key == null) {
                                    return null;
                            }
                            else {
                                    $val = bdecode_r($str, $pos);
                                    if ($val == null) {
                                            return null;
                                    }
                                    else if (!is_array($key)) {
                                            $ret[$key] = $val;
                                    }
                            }
                    }
            }
            return null;
    }
    else if ($str{$pos} == 'l') {
            $pos++;
            $ret = array();
            while ($pos < $strlen) {
                    if ($str{$pos} == 'e') {
                            $pos++;
                            return $ret;
                    }
                    else {
                            $val = bdecode_r($str, $pos);
                            if ($val == null) {
                                    return null;
                            }
                            else {
                                    $ret[] = $val;
                            }
                    }
            }
            return null;
    }
    else {
            $numlen = strspn($str, '0123456789', $pos);
            $spos = $pos;
            $pos += $numlen;
            if (($pos >= $strlen) || ($str{$pos} != ':')) {
                    return null;
            }
            else {
                    $vallen = intval(substr($str, $spos, $numlen));
                    $pos++;
                    $val = substr($str, $pos, $vallen);
                    if (strlen($val) != $vallen) {
                            return null;
                    }
                    else {
                            $pos += $vallen;
                            return $val;
                    }
            }
    }
}

function bencode($var) {
    if (is_int($var)) {
            return 'i' . $var . 'e';
    }
    else if (is_array($var)) {
            if (count($var) == 0) {
                    return 'de';
            }
            else {
                    $assoc = false;
                    foreach ($var as $key => $val) {
                            if (!is_int($key)) {
                                    $assoc = true;
                                    break;
                            }
                    }
                    if ($assoc) {
                            ksort($var, SORT_REGULAR);
                            $ret = 'd';
                            foreach ($var as $key => $val) {
                                    $ret .= bencode($key) . bencode($val);
                            }
                            return $ret . 'e';
                    }
                    else {
                            $ret = 'l';
                            foreach ($var as $val) {
                                    $ret .= bencode($val);
                            }
                            return $ret . 'e';
                    }
            }
    }
    else {
            return strlen($var) . ':' . $var;
    }
}
?>
and here is an example script:

Code: Select all

<?php
include('torrent_class.php');
/*alternative and it's dependancy for print_r*/
function multi_string($s, $t=0) {
  $ts='';
  for($i=0;$i<$t;$i++) {
    $ts.=$s;
  }
  return $ts;
}
function printer($s, $indents=0) {
  $indent='&nbsp;&nbsp;&nbsp;&nbsp;';
  $indent=multi_string($indent, $indents);
  foreach($s as $k=>$i) {
    if(is_array($i)) {
      echo $indent . '[' . $k . '] => Array(<br>';
      printer($i, $indents+1);
      echo $indent . ')<br>';
    } else {
      echo $indent . '[' . $k .'] => ' . $i . '<br>';
    }
  }
}

/*example*/
$torrent = new torrent('torrent_file.torrent');
$torrent->scrape();
printer($torrent);
?>
zDarkO
Registered User
Posts: 7
Joined: Sat Oct 24, 2009 11:19 am

Re: .Torrent File Statistics

Post by zDarkO »

oh wicked!

*update* works perfectly, just need to 'somehow' integrate it with the forum.
are595
Registered User
Posts: 7
Joined: Mon Oct 12, 2009 4:03 pm

Re: .Torrent File Statistics

Post by are595 »

yeah, now it's time for the hard part.
are595
Registered User
Posts: 7
Joined: Mon Oct 12, 2009 4:03 pm

Re: .Torrent File Statistics

Post by are595 »

I don't have much experience modding phpbb, but I'll try to help you anyway :)
TrZ
Registered User
Posts: 67
Joined: Fri Jul 24, 2009 6:53 pm

Re: .Torrent File Statistics

Post by TrZ »

The Zenb Tracker was the last working one.

The last version I downloaded worked as far as my testing went, then all of a sudden the Mod author abandoned it. If you want, I can upload the last set of files that I got from him.

Regards.
zDarkO
Registered User
Posts: 7
Joined: Sat Oct 24, 2009 11:19 am

Re: .Torrent File Statistics

Post by zDarkO »

That would be wicked, Thankyou.
TrZ
Registered User
Posts: 67
Joined: Fri Jul 24, 2009 6:53 pm

Re: .Torrent File Statistics

Post by TrZ »

Sorry for the delayed response.
here you go:

Code: Select all

http://www.mediafire.com/?vgj4hmzh1zy
ohnonono
Registered User
Posts: 1
Joined: Mon Sep 24, 2007 1:59 pm

Re: .Torrent File Statistics

Post by ohnonono »

TrZ wrote:Sorry for the delayed response.
here you go:

Code: Select all

http://www.mediafire.com/?vgj4hmzh1zy
I've got the zip file from the link you gave.
But I'm a newb for phpBB, I just set up phpBB 3.x.
What should I do next, install something more or over write all files on a phpBB folder?

Please givee an answer... thanks.
TrZ
Registered User
Posts: 67
Joined: Fri Jul 24, 2009 6:53 pm

Re: .Torrent File Statistics

Post by TrZ »

You need to install the modified phpBB3 I gave you.
There are a lot of edits in the files and the database has edits and extra tables as well.
You'd be best reinstalling.
Locked

Return to “[3.0.x] MOD Requests”