How to access information from a. torrent file?

Asked

Viewed 357 times

8

I would like to know if it is possible and how to obtain information (Link Magnet, seedes, leechers, peers, size, etc. ) of a file .torrent using PHP.

  • I voted to reopen and regretted it. Just use Google, several results are presented, just choose. It’s a trivially solved problem with a Google search.

  • 4

    @Wineusgobboa.deOliveira so if there is Google, no questions here on Sopt need to exist. The idea is to aggregate relevant content on the site, and this is a doubt that does not exist here yet.

  • @Paulorodrigues this is perhaps a discussion for the goal, which I do not intend to take further. But no, Google is not able to answer all the development questions. Of that I have no doubt.

  • Google serves to at least start a development logic that is missing here, in my first search for the subject I found https://github.com/adriengibrat/torrent-rw

  • 5

    The question was reopened after the opening of meta discussion. @Wineusgobboa.deOliveira The fact that the answer exists on Google does not mean that it does not have space here. Unless the question is too wide (for example, if the answer is the complete documentation of a tool) or has another type of problem. The simple fact that there are answers elsewhere does not invalidate the question here.

  • 3

    Another thing @Viníciusgobboa.deOliveira: please don’t post links to lmgtfy (they sound kind of pejorative, don’t you think?)

  • 1

    @Otto Even if this lib solves the problem, it is in English and does not present any contextual information of as or because works. If we make such a point that people want to learn things, avoiding just "copy and paste" snippets of code on the Internet is the best way. And here we can have much more complete and technical answers.

  • @Gabe relayed the link to help as he was running out of time to set a plausible example. and be less "cool" than the other friend you google.

Show 3 more comments

2 answers

7


A file of torrent contains only metadata, which is information about the target file but no content information of this final file. It’s basically a dictionary of bencode, that 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 around, with this class you can extract this data from a file torrent, 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 I quoted an example above.

As you can observe, only some of this data you quoted is included in the file as the name, parts, size etc, so this partially answers your question. Regarding Seeds, peers and so on, this goes beyond the metadata of the archive, because it involves the entire communication protocol P2P.

2

There is the library libtorrent in C++.

But it also provides a python interface if Voce is 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

  • OP wants an answer for PHP.

  • 6

    @Olimonf. When I answered, on the 29th/04 at 17:59, there was this information, because it was edited 29/04 at 18:20

Browser other questions tagged

You are not signed in. Login or sign up in order to post.