How to access information from a .torrent file?

8

I would like to know if it is possible and how to get information ( magnet link, seedes, leechers, peers, etc.) from a .torrent file using PHP .

    
asked by anonymous 29.04.2015 / 19:23

2 answers

7

A torrent file contains only metadata, which is information about the target file but no content information for this final file. It is basically a dictionary of bencode , which as in this example , contains this structure:

{
     'announce': 'http://bttracker.debian.org:6969/announce',
     'info':
     {
         'name': 'debian-503-amd64-CD-1.iso',
         'piece length': 262144,
         'length': 678428672,
         'pieces': '841ae846bc5b6d7bd6e9aa3dd9e551559c82abc1...d14f1631d776008f83772ee170c42411618190a4'
     }
}

Just one of the examples you can find out there, with this class you can extract this data from a torrent file, just implement something like this to view:

require_once 'class.bdecode.php';

$torrent = new BDecode('arquivo.torrent');
$results = $torrent->result;

Where $results contains the dictionary structure that I cited an example above.

As you can see, only a few of these data you've cited are included in the file, such as name , parts , < then this partially answers your question. In regards to seeds , peers and etc, this goes beyond the file metadata because it involves the entire P2P communication protocol . >     

06.05.2015 / 20:22
2

There is the library libtorrent in C ++.

But it also provides a python interface if you are more comfortable with this language.

import libtorrent
info = libtorrent.torrent_info('test.torrent')
for f in info.files():
    print "%s - %s" % (f.path, f.size)

Source: SO

    
29.04.2015 / 19:59