Class ABCProtocol

Description

ABCProtocol is an abstraction layer to the ABC web interface service (2.7 version)

Variable Summary
string $host
string $last_command
integer $last_error_no
integer $port
integer $timeout
string $unique_key
Method Summary
ABCProtocol ABCProtocol ([string $host = 'localhost'], [integer $port = 4000], [string $unique_key = ''], [integer $timeout = 5])
bool add_torrent (string $torrent, [string $location = ''])
bool add_torrents_list (array $torrents)
bool close ()
bool delete_torrents (mixed $torrents)
mixed get_lang_strings (mixed $names)
mixed get_params (mixed $params)
bool pause_torrents (mixed $torrents)
mixed query ([array $fields = array()])
bool queue_torrents (mixed $torrents)
bool resume_torrents (mixed $torrents)
bool send_command (string $query)
bool set_params (mixed $params)
bool set_torrent_priorities (array $torrents)
bool stop_torrents (mixed $torrents)
bool unpause_torrents (mixed $torrents)
mixed version ()
Variables
string $host = 'localhost' (line 63)
  • var: hostname of computer hosting ABC
string $last_command (line 99)

This property is set when a command is sent

  • var: last command
integer $last_error_no (line 89)

This property is set when an error occurs

ERROR_PROTOCOL errors do not have an error number

  • var: error number
string $last_error_str (line 94)

This property is set when an error occurs

  • var: error string
integer $last_error_type (line 82)

This property is set when an error occurs

  • var: error type (see constants)
integer $port = 4000 (line 67)
  • var: port of computer hosting ABC that ABC is running on
integer $timeout = 5 (line 71)
  • var: number of seconds to timeout connection
string $unique_key = '' (line 76)
  • var: unique key set in ABC
Methods
Constructor ABCProtocol (line 110)

Constructor that defines constants and sets the default class properties

  • version: 1.0
ABCProtocol ABCProtocol ([string $host = 'localhost'], [integer $port = 4000], [string $unique_key = ''], [integer $timeout = 5])
  • string $host: hostname of target computer with ABC
  • integer $port: port of target computer with ABC
  • string $unique_key: unique_key set in ABC
  • integer $timeout: connection timeout
add_torrent (line 826)

Adds a single torrent

Supports setting a save location ONLY IF set parameters and get parameters are enabled in ABC for the web service (disabled by default).

Example Code

  1. $abc->add_torrent( 'http://file1.torrent' );
  2. $abc->add_torrent( 'http://file1.torrent', 'C:\\Downloads\\' );

  • return: the success of the command
  • version: 1.0
bool add_torrent (string $torrent, [string $location = ''])
  • string $torrent: the URL to the torrent file
  • string $location: the save location
add_torrents_list (line 846)

Adds a list of torrents

List of Torrent URLs

  1. $abc->add_torrents_list( array( 'http://file1.torrent', 'http://file2.torrent' ) );
List of Torrent URLs with Save Location
  1. $abc->add_torrents_list( array(
  2. array( 'http://file1.torrent', '/path/to/save/1' ),
  3. array( 'http://file2.torrent', '/path/to/save/2' ) ),
  4. );
Supports setting a save location ONLY IF set parameters and get parameters are enabled in ABC for the web service (disabled by default)

  • return: the success of the command
  • version: 1.0
bool add_torrents_list (array $torrents)
  • array $torrents: pass an array such as array( 'http://file1.torrent', 'http://file2.torrent' ) OR for URLs with save locations, use array( array( 'http://file1.torrent', '/path/to/save/1' ), array( 'http://file2.torrent', '/path/to/save/2' ) )
close (line 205)

Closes ABC's web service

Remember that once you close the web service, there isn't a protocol-based way to get it back up!

Example Code

  1. $abc->close();

  • return: the success of the command
  • version: 1.0
bool close ()
delete_torrents (line 761)

Deletes torrent(s)

Instead of passing an array of torrent hashes, you may also send the following constants:

  • ALL
  • COMPLETED (all tasks with 100% completion)
  • RUNNING (all tasks without 100% completion regardless of status)
Note: ALL and RUNNING are not native features of the protocol so this function automatically sends a query for a list of torrents and then processes that list of torrents.

Example Code
  1. $abc->delete_torrents( array(
  2. 'abcdef01234569abcdef01234569abc1' => 4,
  3. 'abcdef01234569abcdef01234569abc2' => 2,
  4. ) );
  5. $abc->delete_torrents( 'abcdef01234569abcdef01234569abc1' );
  6. $abc->delete_torrents( ALL );
  7. $abc->delete_torrents( COMPLETED );

  • return: the success of the command
  • version: 1.0
bool delete_torrents (mixed $torrents)
  • mixed $torrents: array of torrent info hashes, constant ALL, constant COMPLETED, constant RUNNING, or one info hash as string
get_lang_strings (line 482)

Gets language string from ABC

If you request an inexistant language string from ABC, ABC will popup a message box on the server for the first time that will state that an outdated language file is being used.

Example Code

  1. print_r( $abc->get_lang_strings( array(
  2. 'superseederrornotcompleted',
  3. 'superwarningmsg_line2',
  4. ) ) );
  5. print_r( $abc->get_lang_strings( 'superseederrornotcompleted' ) );

  • return: either an array with string => value for multiple language strings or a value if only one language string was requested
  • version: 1.0
mixed get_lang_strings (mixed $names)
  • mixed $names: either an array of language strings to get or a string of a language string to get
get_params (line 385)

Gets ABC parameter(s)

Example Code

  1. echo $abc->get_params( array( 'window_width', 'maxdownloadrate' ) );
  2. echo $abc->get_params( 'window_width' );

  • return: either an array with param => value for multiple parameters or a value if only one parameter was requested
  • version: 1.0
mixed get_params (mixed $params)
  • mixed $params: either an array of parameters to get or a string of a parameter to get
pause_torrents (line 621)

Pauses torrent(s)

Instead of passing an array of torrent hashes, you may also send the following constants:

  • ALL
  • COMPLETED (all tasks with 100% completion regardless of status)
  • RUNNING (all tasks without 100% completion regardless of status)
Note: COMPLETED and RUNNING are not native features of the protocol so this function automatically sends a query for a list of torrents and then processes that list of torrents.

Example Code
  1. $abc->pause_torrents( array(
  2. 'abcdef01234569abcdef01234569abc1' => 4,
  3. 'abcdef01234569abcdef01234569abc2' => 2,
  4. ) );
  5. $abc->pause_torrents( 'abcdef01234569abcdef01234569abc1' );
  6. $abc->pause_torrents( ALL );
  7. $abc->pause_torrents( COMPLETED );

  • return: the success of the command
  • version: 1.0
bool pause_torrents (mixed $torrents)
  • mixed $torrents: array of torrent info hashes, constant ALL, constant COMPLETED, constant RUNNING, or one info hash as string
query (line 311)

Queries ABC for a list of torrents

Pass an array of fields. If no fields are passed, a default set of fields will be passed.

Note: Do not trust that the order of fields you send are received in the same order (especially if you send repeat fields)

List of Fields (these are constants)

  • COL_FILENAME
  • COL_PROGRESS
  • COL_BT_STATUS
  • COL_PIORITY
  • COL_ETA
  • COL_SIZE
  • COL_DL_SPEED
  • COL_UL_SPEED
  • COL_UD_SIZE
  • COL_MESSAGE
  • COL_SEEDS
  • COL_PEERS
  • COL_COPIES
  • COL_PEER_AVG_PROGRESS
  • COL_DL_SIZE
  • COL_UL_SIZE
  • COL_TOTAL_SPEED
  • COL_TORRENT_NAME
  • COL_DESTINATION
  • COL_SEEDING_TIME
  • COL_CONNECTIONS
  • COL_SEEDING_OPTION
COL_INFO_HASH will be a field gotten AUTOMATICALLY. Do NOT send this as a field! All your query results will have COL_INFO_HASH.

Your results will be an array with keys as the field and the values as the values

Example Code
  1. print_r( $abc->query( array( COL_FILENAME, COL_PROGRESS ) ) );
  2. print_r( $abc->query() );
Example Results (outputted with print_r())
  1. Array
  2. (
  3. [0] => Array
  4. (
  5. [4] => [AonE]_Naruto_142_[A96A4B42].avi
  6. [5] => 100.0%
  7. )
  8. )Array
  9. (
  10. [0] => Array
  11. (
  12. [4] => [AonE]_Naruto_142_[A96A4B42].avi
  13. [5] => 100.0%
  14. [6] => stop
  15. [8] =>
  16. [10] =>
  17. [11] =>
  18. [12] => 49.7%
  19. [15] => 0 (388)
  20. [14] => 0 (531)
  21. [16] =>
  22. [18] => 174.29 MB
  23. [19] => 86.59 MB
  24. [17] =>
  25. [20] =>
  26. [99] => c6ef01d7f1fa5d458e31a37457fead490dfb7bf5
  27. )
  28. )
The key names appear as numbers but you can use $result[0][COL_TORRENT_NAME] or respectively.

  • return: list of current torrents or FALSE for error
  • version: 1.0
mixed query ([array $fields = array()])
  • array $fields: list of fields (the COL_ constants) to get for each torrent - do NOT use COL_INFO_HASH; if $fields is not defined, the default list of fields will be used
queue_torrents (line 733)

Queues torrent(s)

Instead of passing an array of torrent hashes, you may also send the following constants:

  • ALL
  • COMPLETED (all tasks with 100% completion regardless of status)
  • RUNNING (all tasks without 100% completion regardless of status)
Note: COMPLETED and RUNNING are not native features of the protocol so this function automatically sends a query for a list of torrents and then processes that list of torrents.

Example Code
  1. $abc->queue_torrents( array(
  2. 'abcdef01234569abcdef01234569abc1' => 4,
  3. 'abcdef01234569abcdef01234569abc2' => 2,
  4. ) );
  5. $abc->queue_torrents( 'abcdef01234569abcdef01234569abc1' );
  6. $abc->queue_torrents( ALL );
  7. $abc->queue_torrents( COMPLETED );

  • return: the success of the command
  • version: 1.0
bool queue_torrents (mixed $torrents)
  • mixed $torrents: array of torrent info hashes, constant ALL, constant COMPLETED, constant RUNNING, or one info hash as string
resume_torrents (line 677)

Resumes torrent(s)

Instead of passing an array of torrent hashes, you may also send the following constants:

  • ALL
  • COMPLETED (all tasks with 100% completion regardless of status)
  • RUNNING (all tasks without 100% completion regardless of status)
Note: COMPLETED and RUNNING are not native features of the protocol so this function automatically sends a query for a list of torrents and then processes that list of torrents.

Example Code
  1. $abc->resume_torrents( array(
  2. 'abcdef01234569abcdef01234569abc1' => 4,
  3. 'abcdef01234569abcdef01234569abc2' => 2,
  4. ) );
  5. $abc->resume_torrents( 'abcdef01234569abcdef01234569abc1' );
  6. $abc->resume_torrents( ALL );
  7. $abc->resume_torrents( COMPLETED );

  • return: the success of the command
  • version: 1.0
bool resume_torrents (mixed $torrents)
  • mixed $torrents: array of torrent info hashes, constant ALL, constant COMPLETED, constant RUNNING, or one info hash as string
send_command (line 160)

Sends a command to ABC

If there is an error, the error properties of this class will be updated to reflect the error and FALSE will be returned.

Example Code

  1. $abc->send_command( 'CLOSE|' );

  • return: the success of the command; catches both connection errors and errors reported by ABC
  • version: 1.0
bool send_command (string $query)
  • string $query: command line to send to ABC (unique key need not be prepended)
set_params (line 441)

Set ABC parameters

Will return FALSE if one command does not go through.

Note: For each parameter, a new command will be sent. When all the parameters were sent at once, the error Command should end with | kept appearing and a solution could not be found.

Example Code

  1. $abc->set_params( array( 'window_width' => 500 ) );

  • return: the success of the command
  • version: 1.0
bool set_params (mixed $params)
  • mixed $params: either an array of parameters to set or a string of a parameter to set
set_torrent_priorities (line 917)

Sets priorities of torrents

Example Code

  1. $abc->set_torrent_priorities( array(
  2. 'abcdef01234569abcdef01234569abc1' => 4,
  3. 'abcdef01234569abcdef01234569abc2' => 2,
  4. ) );
Piorities range from 0 to 4; use info hashes to identify torrents

Note: For each parameter, a new command will be sent. When all the parameters were sent at once, the error Command should end with | kept appearing and a solution could not be found.

  • return: the success of the command
  • version: 1.0
bool set_torrent_priorities (array $torrents)
  • array $torrents: pass an array such as array( 'abcdef01234569abcdef01234569abc1' => 4,'abcdef01234569abcdef01234569abc2' => 2 ); piorities range from 0 to 4
stop_torrents (line 705)

Stops torrent(s)

Instead of passing an array of torrent hashes, you may also send the following constants:

  • ALL
  • COMPLETED (all tasks with 100% completion regardless of status)
  • RUNNING (all tasks without 100% completion regardless of status)
Note: COMPLETED and RUNNING are not native features of the protocol so this function automatically sends a query for a list of torrents and then processes that list of torrents.

Example Code
  1. $abc->stop_torrents( array(
  2. 'abcdef01234569abcdef01234569abc1' => 4,
  3. 'abcdef01234569abcdef01234569abc2' => 2,
  4. ) );
  5. $abc->stop_torrents( 'abcdef01234569abcdef01234569abc1' );
  6. $abc->stop_torrents( ALL );
  7. $abc->stop_torrents( COMPLETED );

  • return: the success of the command
  • version: 1.0
bool stop_torrents (mixed $torrents)
  • mixed $torrents: array of torrent info hashes, constant ALL, constant COMPLETED, constant RUNNING, or one info hash as string
unpause_torrents (line 649)

Unpauses torrent(s)

Instead of passing an array of torrent hashes, you may also send the following constants:

  • ALL
  • COMPLETED (all tasks with 100% completion regardless of status)
  • RUNNING (all tasks without 100% completion regardless of status)
Note: COMPLETED and RUNNING are not native features of the protocol so this function automatically sends a query for a list of torrents and then processes that list of torrents.

Example Code
  1. $abc->unpause_torrents( array(
  2. 'abcdef01234569abcdef01234569abc1' => 4,
  3. 'abcdef01234569abcdef01234569abc2' => 2,
  4. ) );
  5. $abc->unpause_torrents( 'abcdef01234569abcdef01234569abc1' );
  6. $abc->unpause_torrents( ALL );
  7. $abc->unpause_torrents( COMPLETED );

  • return: the success of the command
  • version: 1.0
bool unpause_torrents (mixed $torrents)
  • mixed $torrents: array of torrent info hashes, constant ALL, constant COMPLETED, constant RUNNING, or one info hash as string
version (line 225)

Gets current version of ABC installed

Example Code

  1. echo $abc->version();

  • return: the version as a string or FALSE for error
  • version: 1.0
mixed version ()

Documentation generated on Fri, 22 Jul 2005 19:04:10 -0700 by phpDocumentor 1.3.0RC3