PHP Class Torrent, torrent-rw

Afficher le fichier Open project: adriengibrat/torrent-rw Class Usage Examples

Protected Properties

Свойство Type Description
$_errors List of error occured

Méthodes publiques

Méthode 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 )

Méthodes protégées

Méthode 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

Méthode 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 méthode

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 méthode

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

announce() public méthode

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
Résultat string | array | null announce url / list or null if not set

announce_list() protected static méthode

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

build() protected méthode

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

comment() public méthode

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

content() public méthode

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

decode() protected static méthode

Decode torrent data or file
protected static decode ( $string ) : array
Résultat array decoded torrent data

encode() public static méthode

Encode torrent data
public static encode ( $mixed ) : string
Résultat string torrent encoded data

error() public méthode

Return last error message
public error ( ) : string | boolean
Résultat string | boolean last error message or false if none

errors() public méthode

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

file_get_contents() public static méthode

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

filesize() public static méthode

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

first_announce() protected static méthode

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

fopen() public static méthode

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

format() public static méthode

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

hash_info() public méthode

Compute hash info
public hash_info ( ) : string
Résultat string hash info or null if info not set

httpseeds() public méthode

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

is_list() protected static méthode

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

is_private() public méthode

Getter and setter of private flag
public is_private ( $private = null ) : boolean
Résultat boolean private flag

is_torrent() public static méthode

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

is_url() public static méthode

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

magnet() public méthode

Get magnet link
public magnet ( $html = true ) : string
Résultat string magnet link

name() public méthode

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

offset() public méthode

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

pack() protected static méthode

Helper to pack data hash
protected static pack ( &$data ) : string
Résultat string packed data hash

path() protected static méthode

Helper to build file path
protected static path ( $path, $folder ) : string
Résultat string real file path

path_explode() protected static méthode

Helper to explode file path
protected static path_explode ( $path ) : array
Résultat array file path

piece_length() public méthode

Get piece length
public piece_length ( ) : integer
Résultat integer piece length or null if not set

save() public méthode

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

scandir() public static méthode

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

scrape() public méthode

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

send() public méthode

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

set_error() protected static méthode

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

size() public méthode

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

source() public méthode

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

touch() protected méthode

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

untier() public static méthode

Flatten announces list
public static untier ( $announces ) : array
Résultat array flattened annonces list

url_exists() public static méthode

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

url_list() public méthode

Getter and setter of webseed(s) url list ( GetRight implementation )
public url_list ( $urls = null ) : string | array | null
Résultat 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