Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Downloads (http://www.bvlist.com/forumdisplay.php?f=16)
-   -   php-bittorrent (http://www.bvlist.com/showthread.php?t=7887)

Phogo 2nd May 2012 14:32

php-bittorrent
 
PHP classes for encoding/decoding data to/from the BitTorrent format, creating torrent files and running your own tracker.

Credits: Christer Edvartsen
Download: here

PHP_BitTorrent

PHP_BitTorrent is a library that provides PHP classes that can be used to encode/decode to/from the BitTorrent format. It also provides tracker classes that can be used to run your own BitTorrent tracker. The package is not a complete tracker system like for instance btit.
Requirements

PHP_BitTorrent requires PHP 5.3.x or above.
Installation

PHP_BitTorrent should be installed using PEAR.
The PEAR channel (pear.starzinger.net) that is used to distribute PHP_BitTorrent needs to be registered with the local PEAR environment.


Code:

christer@aurora:~$ sudo pear channel-discover pear.starzinger.net Adding Channel "pear.starzinger.net" succeeded Discovery of channel "pear.starzinger.net" succeeded
This has to be done only once. Now, to install the package:
Code:

christer@aurora:~$ sudo pear install stz/PHP_BitTorrent-alpha downloading PHP_BitTorrent-0.0.1.tgz ... Starting to download PHP_BitTorrent-0.0.1.tgz (8,037 bytes) .....done: 8,037 bytes install ok: channel://pear.starzinger.net/PHP_BitTorrent-0.0.1
Using the PHP_BitTorrent API

Encode PHP variables
Code:

'bar', 'bar' => 'foo')); // string(22) "d3:foo3:bar3:bar3:fooe"
There is also a convenience method simply called encode in the PHP_BitTorrent_Encoder class that can be used to encode all encodable variables. Only integers, strings and arrays can be encoded to the BitTorrent format.
Decode BitTorrent encoded data
Code:

int(1) [1]=> int(2) [2]=> int(3) } var_dump(PHP_BitTorrent_Decoder::decodeDictionary('d3:foo3:bar3:bar3:fooe'); // array(2) { ["foo"]=> string(3) "bar" ["bar"]=> string(3) "foo" }
There is also a convenience method called decode that can decode any bittorrent endocded data.
Decode torrent files
The decoder class also has a method for decoding a torrent file (which is an encoded dictionary):
Code:


Create new torrent files and open existing ones
The PHP_BitTorrent_Torrent class represents a torrent file and can be used to create torrent files.
Code:

setAnnounce('http://tracker/announce.php')        ->setComment('Some comment')        ->loadFromPath('/path/to/files')        ->save('/save/path/file.torrent');
The class can also load a torrent file:
Code:

loadFromTorrentFile('/path/to/file.torrent')        ->setAnnounce('http://tracker/announce.php') // Override announce in original file        ->setComment('Some comment') // Override commend in original file        ->save('/save/path/file.torrent'); // Save to a new file


All times are GMT +2. The time now is 10:55.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.