Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Generowanie magnet linku
Forum PHP.pl > Forum > PHP
k00sl
Witam serdecznie,

Od pewnego czasu próbuję stworzyć generatora magnet linków. Tak jak tutaj: http://centrump2p.com/magnet/


Przykładowo posiadam taki info_hash:

8905762b8851be015260b72d92b34cf55bcdb254 // 40 znaków

Po generatorze centrump2p.com wygląda on tak:

RECXMK4IKG7ACUTAW4WZFM2M6VN43MSU // 32 znaki


Dokumentacje:

vuze.com ( http://wiki.vuze.com/w/Magnet_link ):
The magnet link consists of the prefix magnet:?xt=urn:btih: and the base32() encoded SHA1 of the torrent's info dictionary (known as torrent-hash or infohash). Please note that's the base32-encoding of the torrent-hash's binary (20byte) representation, not the hexadecimal representation.

bittorrent.org ( http://bittorrent.org/beps/bep_0009.html ):
Is the info-hash hex encoded, for a total of 40 characters. For compatability with existing links in the wild, clients should also support the 32 character base32 [1] encoded info-hash.


Próbuję w ten sposób


magnet.php
  1. <?php
  2.  
  3. include('class.base32.php5');
  4.  
  5. $info_hash = '8905762b8851be015260b72d92b34cf55bcdb254';
  6.  
  7. $b = new Base32(Base32::csRFC3548);
  8. print $b->fromString($info_hash);
  9.  
  10. ?>


Klasa base32 znajduję się tutaj: http://fremnet.net/article/215/class-base32


No i niestety wygląda to tak, że otrzymuję 64 znakowy ciąg (powinien być 32):

HA4TANJXGYZGEOBYGUYWEZJQGE2TENRQMI3TEZBZGJRDGNDDMY2TKYTDMRRDENJU


Bardzo proszę o pomoc przy tym kodowaniu,

Pozdrawiam.
Noidea
Sam sobie odpowiedziałeś wklejając kawałek dokumentacji smile.gif
Cytat
Please note that's the base32-encoding of the torrent-hash's binary (20byte) representation, not the hexadecimal representation.



  1. <?php
  2.  
  3. include( 'class.base32.php5' );
  4.  
  5. $info_hash = pack( 'H*', '8905762b8851be015260b72d92b34cf55bcdb254' );
  6.  
  7. $b = new Base32( Base32::csRFC3548 );
  8. print $b->fromString( $info_hash );
  9.  
  10. ?>
k00sl
oto właśnie chodziło, dziękuję
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.