PHP Class Torrent, torrent-rw

Datei anzeigen Open project: adriengibrat/torrent-rw Class Usage Examples

Protected Properties

Property Type Description
$_errors List of error occured

Public Methods

Method Description
__construct ( $data = null, $meta = [], $piece_length = 256 ) Read and decode torrent file/data OR build a torrent from source folder/file(s) Supported signatures: - Torrent(); // get an instance (usefull to scrape and check errors) - Torrent( string $torrent ); // analyse a torrent file - Torrent( string $torrent, string $announce ); - Torrent( string $torrent, array $meta ); - Torrent( string $file_or_folder ); // create a torrent file - Torrent( string $file_or_folder, string $announce_url, [int $piece_length] ); - Torrent( string $file_or_folder, array $meta, [int $piece_length] ); - Torrent( array $files_list ); - Torrent( array $files_list, string $announce_url, [int $piece_length] ); - Torrent( array $files_list, array $meta, [int $piece_length] );
__toString ( ) : string Convert the current Torrent instance in torrent format
announce ( $announce = null ) : string | array | null Getter and setter of torrent announce url / list If the argument is a string, announce url is added to announce list (or set as announce if announce is not set) If the argument is an array/object, set announce url (with first url) and list (if array has more than one url), tiered list supported If the argument is false announce url & list are unset
comment ( $comment = null ) : string | null Getter and setter of torrent comment
content ( $precision = null ) : array List torrent content
encode ( $mixed ) : string Encode torrent data
error ( ) : string | boolean Return last error message
errors ( ) : array | boolean Return Errors
file_get_contents ( $file, $timeout = self::timeout, $offset = null, $length = null ) : string | boolean Helper to get (distant) file content
filesize ( $file ) : double | boolean Helper to return filesize (even bigger than 2Gb -linux only- and distant files size)
fopen ( $file, $size = null ) : ressource | boolean Helper to open file to read (even bigger than 2Gb, linux only)
format ( $size, $precision = 2 ) : string Helper to format size in bytes to human readable
hash_info ( ) : string Compute hash info
httpseeds ( $urls = null ) : array | null Getter and setter of httpseed(s) url list ( Bittornado implementation )
is_private ( $private = null ) : boolean Getter and setter of private flag
is_torrent ( $file, $timeout = self::timeout ) : boolean Helper to check if a file is a torrent
is_url ( $url ) : boolean Helper to check if string is an url (http)
magnet ( $html = true ) : string Get magnet link
name ( $name = null ) : string | null Getter and setter of torrent name
offset ( ) : array List torrent content pieces and offset(s)
piece_length ( ) : integer Get piece length
save ( $filename = null ) : boolean Save torrent file to disk
scandir ( $dir ) : array Helper to scan directories files and sub directories recursivly
scrape ( $announce = null, $hash_info = null, $timeout = self::timeout ) * static
send ( $filename = null ) : void Send torrent file to client
size ( $precision = null ) : integer | string Sum torrent content size
source ( $source = null ) : string | null Getter and setter of torrent source
untier ( $announces ) : array Flatten announces list
url_exists ( $url ) : boolean Helper to check if url exists
url_list ( $urls = null ) : string | array | null Getter and setter of webseed(s) url list ( GetRight implementation )

Protected Methods

Method Description
announce_list ( $announce, $merge = [] ) : array Build announce list
build ( $data, $piece_length ) : array | boolean Build torrent info
decode ( $string ) : array Decode torrent data or file
first_announce ( $announce ) : string Get the first announce url in a list
is_list ( $array ) : boolean Helper to test if an array is a list
pack ( &$data ) : string Helper to pack data hash
path ( $path, $folder ) : string Helper to build file path
path_explode ( $path ) : array Helper to explode file path
set_error ( $exception, $message = false ) : boolean | string Add an error to errors stack
touch ( $void = null ) : any Set torrent creator and creation date

Private Methods

Method Description
char ( $data ) : string | boolean Helper to return the first char of encoded data
decode_data ( &$data ) : array Decode torrent data
decode_dictionary ( &$data ) : array Decode torrent dictionary
decode_integer ( &$data ) : integer Decode torrent integer
decode_list ( &$data ) : array Decode torrent list
decode_string ( &$data ) : string Decode torrent string
encode_array ( $array ) : string Encode torrent dictionary or list
encode_integer ( $integer ) : string Encode torrent integer
encode_string ( $string ) : string Encode torrent string
file ( $file, $piece_length ) : array Build torrent info from single file
files ( $files, $piece_length ) : array Build torrent info from files
folder ( $dir, $piece_length ) : array Build torrent info from folder content
pieces ( $handle, $piece_length, $last = true ) : string Build pieces depending on piece length from a file handler

Method Details

__construct() public method

Read and decode torrent file/data OR build a torrent from source folder/file(s) Supported signatures: - Torrent(); // get an instance (usefull to scrape and check errors) - Torrent( string $torrent ); // analyse a torrent file - Torrent( string $torrent, string $announce ); - Torrent( string $torrent, array $meta ); - Torrent( string $file_or_folder ); // create a torrent file - Torrent( string $file_or_folder, string $announce_url, [int $piece_length] ); - Torrent( string $file_or_folder, array $meta, [int $piece_length] ); - Torrent( array $files_list ); - Torrent( array $files_list, string $announce_url, [int $piece_length] ); - Torrent( array $files_list, array $meta, [int $piece_length] );
public __construct ( $data = null, $meta = [], $piece_length = 256 )

__toString() public method

Convert the current Torrent instance in torrent format
public __toString ( ) : string
return string encoded torrent data

announce() public method

Getter and setter of torrent announce url / list If the argument is a string, announce url is added to announce list (or set as announce if announce is not set) If the argument is an array/object, set announce url (with first url) and list (if array has more than one url), tiered list supported If the argument is false announce url & list are unset
public announce ( $announce = null ) : string | array | null
return string | array | null announce url / list or null if not set

announce_list() protected static method

Build announce list
protected static announce_list ( $announce, $merge = [] ) : array
return array announce list (array of arrays)

build() protected method

Build torrent info
protected build ( $data, $piece_length ) : array | boolean
return array | boolean torrent info or false if data isn't folder/file(s)

comment() public method

Getter and setter of torrent comment
public comment ( $comment = null ) : string | null
return string | null comment or null if not set

content() public method

List torrent content
public content ( $precision = null ) : array
return array file(s) and size(s) list, files as keys and sizes as values

decode() protected static method

Decode torrent data or file
protected static decode ( $string ) : array
return array decoded torrent data

encode() public static method

Encode torrent data
public static encode ( $mixed ) : string
return string torrent encoded data

error() public method

Return last error message
public error ( ) : string | boolean
return string | boolean last error message or false if none

errors() public method

Return Errors
public errors ( ) : array | boolean
return array | boolean error list or false if none

file_get_contents() public static method

Helper to get (distant) file content
public static file_get_contents ( $file, $timeout = self::timeout, $offset = null, $length = null ) : string | boolean
return string | boolean file content or false if error

filesize() public static method

Helper to return filesize (even bigger than 2Gb -linux only- and distant files size)
public static filesize ( $file ) : double | boolean
return double | boolean filesize or false if error

first_announce() protected static method

Get the first announce url in a list
protected static first_announce ( $announce ) : string
return string first announce url

fopen() public static method

Helper to open file to read (even bigger than 2Gb, linux only)
public static fopen ( $file, $size = null ) : ressource | boolean
return ressource | boolean file handle or false if error

format() public static method

Helper to format size in bytes to human readable
public static format ( $size, $precision = 2 ) : string
return string formated size in appropriate unit

hash_info() public method

Compute hash info
public hash_info ( ) : string
return string hash info or null if info not set

httpseeds() public method

Getter and setter of httpseed(s) url list ( Bittornado implementation )
public httpseeds ( $urls = null ) : array | null
return array | null httpseed(s) or null if not set

is_list() protected static method

Helper to test if an array is a list
protected static is_list ( $array ) : boolean
return boolean is the array a list or not

is_private() public method

Getter and setter of private flag
public is_private ( $private = null ) : boolean
return boolean private flag

is_torrent() public static method

Helper to check if a file is a torrent
public static is_torrent ( $file, $timeout = self::timeout ) : boolean
return boolean is the file a torrent or not

is_url() public static method

Helper to check if string is an url (http)
public static is_url ( $url ) : boolean
return boolean is string an url

magnet() public method

Get magnet link
public magnet ( $html = true ) : string
return string magnet link

name() public method

Getter and setter of torrent name
public name ( $name = null ) : string | null
return string | null name or null if not set

offset() public method

List torrent content pieces and offset(s)
public offset ( ) : array
return array file(s) and pieces/offset(s) list, file(s) as keys and pieces/offset(s) as values

pack() protected static method

Helper to pack data hash
protected static pack ( &$data ) : string
return string packed data hash

path() protected static method

Helper to build file path
protected static path ( $path, $folder ) : string
return string real file path

path_explode() protected static method

Helper to explode file path
protected static path_explode ( $path ) : array
return array file path

piece_length() public method

Get piece length
public piece_length ( ) : integer
return integer piece length or null if not set

save() public method

Save torrent file to disk
public save ( $filename = null ) : boolean
return boolean file has been saved or not

scandir() public static method

Helper to scan directories files and sub directories recursivly
public static scandir ( $dir ) : array
return array directory content list

scrape() public method

* static
public scrape ( $announce = null, $hash_info = null, $timeout = self::timeout )

send() public method

Send torrent file to client
public send ( $filename = null ) : void
return void script exit

set_error() protected static method

Add an error to errors stack
protected static set_error ( $exception, $message = false ) : boolean | string
return boolean | string return false or error message if requested

size() public method

Sum torrent content size
public size ( $precision = null ) : integer | string
return integer | string file(s) size

source() public method

Getter and setter of torrent source
public source ( $source = null ) : string | null
return string | null source or null if not set

touch() protected method

Set torrent creator and creation date
protected touch ( $void = null ) : any
return any param

untier() public static method

Flatten announces list
public static untier ( $announces ) : array
return array flattened annonces list

url_exists() public static method

Helper to check if url exists
public static url_exists ( $url ) : boolean
return boolean does the url exist or not

url_list() public method

Getter and setter of webseed(s) url list ( GetRight implementation )
public url_list ( $urls = null ) : string | array | null
return string | array | null webseed(s) or null if not set

Property Details

$_errors protected_oe static_oe property

List of error occured
protected static $_errors