Sending scrape request for getting torrent's seeds and peers
Asked Answered
R

1

7

I have been trying to create a torrent site but I'm stuck with the following. How to send torrent scrape request to get its seeder and leechers?

I have a PHP class function that provides me announce list.

public function getTrackers() {
    // Load tracker list
    $trackerlist = array();

    if ( $this->torrent->get_value('announce-list') )
    {
        $trackers = $this->torrent->get_value('announce-list')->get_plain();
        while ( list( $key, $value ) = each( $trackers ) )
        {
            if ( is_array( $value->get_plain() ) ) {
                while ( list( $key, $value2 ) = each( $value ) )
                {
                    while ( list( $key, $value3 ) = each( $value2 ) )
                    {
                        array_push( $trackerlist, $value3->get_plain() );
                    }
                }
            } else {
                array_push( $trackerlist, $value->get_plain() );
            }
        }
    }
    else if ( $this->torrent->get_value('announce') )
    {
        array_push( $trackerlist, $this->torrent->get_value('announce')->get_plain() );
    }

    return $trackerlist;
}

This code is based on the data encoded by the bencode.php. How to show Seeds and Peers of every consecutive announce url like this?

Annouce Url | Seeds : No. | Peers: No.     
Annouce Url | Seeds : No. | Peers: No.     
Annouce Url | Seeds : No. | Peers: No. 
and so on.....
Riedel answered 28/2, 2011 at 9:42 Comment(0)
N
5

I can't help you with code, due to my limited experience with PHP, but dealing with HTTP trackers should be fairly easy.

Get the announce URL, search and replace the word "announce" with "scrape" and add ?infohash=<url-encoded-binary-20-byte-long-infohash> as parameter (you may add as many infohash= to your query, divided by ampersand. Make a HTTP call to that resulting URL and read your bencoded answer. It will contain all the requested info-hashes with their respective downloads, seeders ('complete' in tracker's vocabulary) and leechers ('incomplete'). HTTP scrape is very well documented.

Dealing with UDP trackers is somewhat more complicated, because this binary form of communication happens at much lower level. Check the full description of UDP tracker protocol.

Notate answered 6/3, 2011 at 19:47 Comment(2)
Why doesn't this: xbtt.sourceforge.net/udp_tracker_protocol.html have peers list of IP addresses? contrary to documentation here wiki.theory.org/BitTorrent_Tracker_ProtocolForepart
Information-wise there's no difference between HTTP & UDP. Most probably you compare apples with bananas, namely mixing UDP scrape with HTTP announce. UDP announce gets peers exactly like HTTP announce does. Both HTTP and UDP scrape will give you no actual peers, but counters. Hope this clarifies your confusion.Notate

© 2022 - 2024 — McMap. All rights reserved.