How to get the magnet link from a .torrent file?

-2

I can get information from .torrent files using the class Torrent RW or Torrent-parse , such as file name, size , HASH , etc.

I would also like to get the magnet link , however I'm having trouble proceeding with this, how can I extract this information using either of these two classes?

    
asked by anonymous 11.05.2015 / 20:21

1 answer

3

Torrent RW does not have a function that returns the Magnet Link > . Only Torrent-parse , through the function magnet() . Here's an example:

error_reporting(E_STRICT);
include 'Torrent.php';

$torrent = new Torrent('tails-i386-1.2.3.torrent');

echo "<pre>";
echo "Nome do arquivo: ". $torrent->name()                . "<br>";
echo "Tamanho: ". $torrent->size(2)                       . "<br>";
echo "Piece length: ". $torrent->piece_length()           . "<br>";
echo "HASH: ". $torrent->hash_info()                      . "<br>";
echo 'Privado: '. ($torrent->is_private() ? 'Sim' : 'Não'). "<br>";
echo 'Comentário: '. $torrent->comment()                  . "<br>";
echo 'Anúncio: '. $torrent->announce()                    . "<br>";
echo 'Status: ', var_dump($torrent->scrape())             . "<br>";
echo "Magnet link: ". $torrent->magnet()                  . "<br>";

The output will look something like this:

Nome do arquivo: tails-i386-1.2.3
Tamanho: 907.67 Mo
Piece length: 262144
HASH: 957a82ee0d2fb0938952167d6c34dbf7e37a8946
Privado: Não
Comentário: 
Anúncio: http://torrent.gresille.org/announce
Status: array(1) {
  ["http://torrent.gresille.org/scrape"]=>
  array(3) {
    ["complete"]=>
    int(239)
    ["downloaded"]=>
    int(8)
    ["incomplete"]=>
    int(0)
  }
}

Magnet link: magnet:?xt=urn:btih:957a82ee0d2fb0938952167d6c34dbf7e37a8946&dn=tails-i386-1.2.3&xl=951765793&tr=http://torrent.gresille.org/announce
    
11.05.2015 / 21:26