jeankassio/php-deluge-console

通过 PHP 连接到 Deluge 客户端/服务器控制台,带有预定义的函数和打开控制台发送命令。

0.2.1 2022-08-23 15:46 UTC

This package is auto-updated.

Last update: 2024-09-28 23:51:40 UTC


README

通过 PHP 连接到 Deluge-Torrent 客户端/服务器控制台,带有预定义的函数和打开控制台发送命令。

Total Downloads License: MIT

来自 deluge console 的 Php 包

安装

 composer require jeankassio/php-deluge-console

如何使用

require dirname(__FILE__) . '/vendor/autoload.php';

use JeanKassio\Deluge\Console;
use JeanKassio\Deluge\DelugeFunctions\BasicFunctions;
 
 /*
 Here you configure the connection settings.
 */
 
 $config = array(
	'console_command' => 'deluge-console', 	//optional, default is 'deluge-console'
	'host' => 'localhost',  		//optional, default is 'localhost'
	'port' => '58846',  			//optional, default is '58846'
	'user' => 'username',
	'pass' => 'password',
);

/*
Instancing a new Console
*/

$console = new Console($config);

/*
Here you call the method you want.
Let's in this example add a new torrent.
*/

/*
The first parameter is the Path where the file we are going to download will be saved.
The second parameter is the Magnet Link or the location where the .torrent file is stored.
*/
  
$id = 0; //Get id value from something
$id++;
$name = "file.torrent";
$c_torrent = dirname(__FILE__, 2) . "/content/torrent/$name";
$path = dirname(__FILE__, 2) . "/content/download/$id/";
		
if (!file_exists($path)) {
  mkdir($path, 0777, true); //Here I am creating a directory to save my file
  chmod($path, 0777);       //Here I am setting the permissions to 777, this is the permission level that Deluge needs so that the download can start normally.
}
  
/*
Here I am finally submitting the information and adding the torrent to Deluge
*/

$response = (new BasicFunctions($console))->addtorrent($path, $c_torrent);
 

其他现有方法

获取 torrent 列表

require dirname(__FILE__) . '/vendor/autoload.php';

use JeanKassio\Deluge\Console;
use JeanKassio\Deluge\DelugeFunctions\BasicFunctions;

$config = array(
	'console_command' => 'deluge-console', 	//optional, default is 'deluge-console'
	'host' => 'localhost',  		//optional, default is 'localhost'
	'port' => '58846',  			//optional, default is '58846'
	'user' => 'username',
	'pass' => 'password',
);

$console = new Console($config);

$torrents = (new BasicFunctions($console))->torrentList();

foreach($torrents as $torrent){

	var_dump($torrent);			

}

获取单个 Torrent

require dirname(__FILE__) . '/vendor/autoload.php';

use JeanKassio\Deluge\Console;
use JeanKassio\Deluge\DelugeFunctions\BasicFunctions;

$config = array(
	'console_command' => 'deluge-console', 	//optional, default is 'deluge-console'
	'host' => 'localhost',  		//optional, default is 'localhost'
	'port' => '58846',  			//optional, default is '58846'
	'user' => 'username',
	'pass' => 'password',
);

$console = new Console($config);

$torrent_id = "9c62d55c744642ef3f6f6daa3448055fb490a12e";

$torrent = (new BasicFunctions($console))->torrent($torrent_id);

var_dump($torrent);

控制台,以进行自定义调用

require dirname(__FILE__) . '/vendor/autoload.php';

use JeanKassio\Deluge\Console;
use JeanKassio\Deluge\DelugeFunctions\BasicFunctions;

$config = array(
	'console_command' => 'deluge-console', 	//optional, default is 'deluge-console'
	'host' => 'localhost',  		//optional, default is 'localhost'
	'port' => '58846',  			//optional, default is '58846'
	'user' => 'username',
	'pass' => 'password',
);

$console = new Console($config);

$command = "status";

$response = (new BasicFunctions($console))->console($command);

var_dump($response);

新方法

所有这些函数始终返回 null

require dirname(__FILE__) . '/vendor/autoload.php';

use JeanKassio\Deluge\Console;
use JeanKassio\Deluge\DelugeFunctions\BasicFunctions;

$config = array(
	'console_command' => 'deluge-console', 	//optional, default is 'deluge-console'
	'host' => 'localhost',  		//optional, default is 'localhost'
	'port' => '58846',  			//optional, default is '58846'
	'user' => 'username',
	'pass' => 'password',
);

$console = new Console($config);

$bFunction = new BasicFunctions($console);


$bFunction->pause(true); //Pause all torrents

$bFunction->pause(false, array("9c62d55c744642ef3f6f6daa3448055fb490a12e","57a30a85b4a8375fc7a05a05c5f47e28b34da087")); //Pause only torrents listed with your ID



$bFunction->recheck(true); //Recheck on all torrents

$bFunction->recheck(false, array("9c62d55c744642ef3f6f6daa3448055fb490a12e","57a30a85b4a8375fc7a05a05c5f47e28b34da087")); //Recheck only on torrents listed with your ID



$bFunction->resume(true); //Resume all torrents

$bFunction->resume(false, array("9c62d55c744642ef3f6f6daa3448055fb490a12e","57a30a85b4a8375fc7a05a05c5f47e28b34da087")); //Resume only torrents listed with your ID



$bFunction->remove(array("9c62d55c744642ef3f6f6daa3448055fb490a12e","57a30a85b4a8375fc7a05a05c5f47e28b34da087")); //Delete the torrent without deleting the files

$bFunction->remove(array("9c62d55c744642ef3f6f6daa3448055fb490a12e","57a30a85b4a8375fc7a05a05c5f47e28b34da087"), true); //Delete the torrent and the files



修改自 deluge-php 的包