PHP Класс Torrent, torrent-rw

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_errors List of error occured

Открытые методы

Метод Описание
__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 )

Защищенные методы

Метод Описание
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

Приватные методы

Метод Описание
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

Описание методов

__construct() публичный Метод

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() публичный Метод

Convert the current Torrent instance in torrent format
public __toString ( ) : string
Результат string encoded torrent data

announce() публичный Метод

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
Результат string | array | null announce url / list or null if not set

announce_list() защищенный статический Метод

Build announce list
protected static announce_list ( $announce, $merge = [] ) : array
Результат array announce list (array of arrays)

build() защищенный Метод

Build torrent info
protected build ( $data, $piece_length ) : array | boolean
Результат array | boolean torrent info or false if data isn't folder/file(s)

comment() публичный Метод

Getter and setter of torrent comment
public comment ( $comment = null ) : string | null
Результат string | null comment or null if not set

content() публичный Метод

List torrent content
public content ( $precision = null ) : array
Результат array file(s) and size(s) list, files as keys and sizes as values

decode() защищенный статический Метод

Decode torrent data or file
protected static decode ( $string ) : array
Результат array decoded torrent data

encode() публичный статический Метод

Encode torrent data
public static encode ( $mixed ) : string
Результат string torrent encoded data

error() публичный Метод

Return last error message
public error ( ) : string | boolean
Результат string | boolean last error message or false if none

errors() публичный Метод

Return Errors
public errors ( ) : array | boolean
Результат array | boolean error list or false if none

file_get_contents() публичный статический Метод

Helper to get (distant) file content
public static file_get_contents ( $file, $timeout = self::timeout, $offset = null, $length = null ) : string | boolean
Результат string | boolean file content or false if error

filesize() публичный статический Метод

Helper to return filesize (even bigger than 2Gb -linux only- and distant files size)
public static filesize ( $file ) : double | boolean
Результат double | boolean filesize or false if error

first_announce() защищенный статический Метод

Get the first announce url in a list
protected static first_announce ( $announce ) : string
Результат string first announce url

fopen() публичный статический Метод

Helper to open file to read (even bigger than 2Gb, linux only)
public static fopen ( $file, $size = null ) : ressource | boolean
Результат ressource | boolean file handle or false if error

format() публичный статический Метод

Helper to format size in bytes to human readable
public static format ( $size, $precision = 2 ) : string
Результат string formated size in appropriate unit

hash_info() публичный Метод

Compute hash info
public hash_info ( ) : string
Результат string hash info or null if info not set

httpseeds() публичный Метод

Getter and setter of httpseed(s) url list ( Bittornado implementation )
public httpseeds ( $urls = null ) : array | null
Результат array | null httpseed(s) or null if not set

is_list() защищенный статический Метод

Helper to test if an array is a list
protected static is_list ( $array ) : boolean
Результат boolean is the array a list or not

is_private() публичный Метод

Getter and setter of private flag
public is_private ( $private = null ) : boolean
Результат boolean private flag

is_torrent() публичный статический Метод

Helper to check if a file is a torrent
public static is_torrent ( $file, $timeout = self::timeout ) : boolean
Результат boolean is the file a torrent or not

is_url() публичный статический Метод

Helper to check if string is an url (http)
public static is_url ( $url ) : boolean
Результат boolean is string an url

magnet() публичный Метод

Get magnet link
public magnet ( $html = true ) : string
Результат string magnet link

name() публичный Метод

Getter and setter of torrent name
public name ( $name = null ) : string | null
Результат string | null name or null if not set

offset() публичный Метод

List torrent content pieces and offset(s)
public offset ( ) : array
Результат array file(s) and pieces/offset(s) list, file(s) as keys and pieces/offset(s) as values

pack() защищенный статический Метод

Helper to pack data hash
protected static pack ( &$data ) : string
Результат string packed data hash

path() защищенный статический Метод

Helper to build file path
protected static path ( $path, $folder ) : string
Результат string real file path

path_explode() защищенный статический Метод

Helper to explode file path
protected static path_explode ( $path ) : array
Результат array file path

piece_length() публичный Метод

Get piece length
public piece_length ( ) : integer
Результат integer piece length or null if not set

save() публичный Метод

Save torrent file to disk
public save ( $filename = null ) : boolean
Результат boolean file has been saved or not

scandir() публичный статический Метод

Helper to scan directories files and sub directories recursivly
public static scandir ( $dir ) : array
Результат array directory content list

scrape() публичный Метод

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

send() публичный Метод

Send torrent file to client
public send ( $filename = null ) : void
Результат void script exit

set_error() защищенный статический Метод

Add an error to errors stack
protected static set_error ( $exception, $message = false ) : boolean | string
Результат boolean | string return false or error message if requested

size() публичный Метод

Sum torrent content size
public size ( $precision = null ) : integer | string
Результат integer | string file(s) size

source() публичный Метод

Getter and setter of torrent source
public source ( $source = null ) : string | null
Результат string | null source or null if not set

touch() защищенный Метод

Set torrent creator and creation date
protected touch ( $void = null ) : any
Результат any param

untier() публичный статический Метод

Flatten announces list
public static untier ( $announces ) : array
Результат array flattened annonces list

url_exists() публичный статический Метод

Helper to check if url exists
public static url_exists ( $url ) : boolean
Результат boolean does the url exist or not

url_list() публичный Метод

Getter and setter of webseed(s) url list ( GetRight implementation )
public url_list ( $urls = null ) : string | array | null
Результат string | array | null webseed(s) or null if not set

Описание свойств

$_errors защищенное статическое свойство

List of error occured
protected static $_errors