happydemon/transmission

调用Transmission守护进程RPC接口的小助手

0.3 2017-08-26 12:35 UTC

This package is auto-updated.

Last update: 2024-09-12 22:04:32 UTC


README

您可以使用此包与您的Transmission安装的web/RPC服务器通信。

您可以通过进入“首选项”>“远程”>“启用远程访问”来设置Transmission。

此包针对Transmission的RPC规范编写,如果您需要更多关于每个调用做什么或返回什么数据的信息,这是最佳起点。

安装

首先,您需要引入库

composer require happydemon/transmission

简短介绍

接下来,您需要设置Transmission对象。

$transmission = new \HappyDemon\Transmission\Transmission();

如果不定义任何配置,对象将使用合理的默认值来连接到Transmission。

让我们检索Transmission中我们拥有的种子列表

var_dump($transmission->torrents()->get());

配置

在初始化一个Transmission对象时,您可以传递一个包含多个配置选项的数组;

ssl 布尔值

Transmission web服务器是通过https提供的吗?

host 字符串

Transmission web服务器运行在哪个主机/IP上(默认为127.0.0.1)。

port 字符串

Transmission web服务器运行在哪个端口上(默认为9091)。

url 字符串

Transmission web服务器运行在哪个端点上(默认为/transmission/rpc)。

username 字符串

用于认证的用户名是什么?(默认为空)

password 字符串

用于认证的密码是什么?(默认为空)

主要种子方法

检索种子

检索您在Transmission中看到的种子列表。

$transmission->torrents()->get();

这将始终返回一个包含HappyDemon\Services\Transmission\Torrents\Entity对象的数组。您可以通过查看该类来了解可用的属性。

您也可以用它来检索具有ID的单个或多个种子

// Get the torrent with id 1
$transmission->torrents()->get(1);


// Get a few torrents
$transmission->torrents()->get([1,6,12]);

添加种子

$torrent = $transmission->torrents()->addFromUrl($urlToTorrent);
$torrent = $transmission->torrents()->addFile($filePath);
$torrent = $transmission->torrents()->addFromBase64($fileBlob);

使用这些方法中的任何一个都可以让您添加新的种子。每次它都会返回一个HappyDemon\Services\Transmission\Torrents\Entity对象。但问题是,只有3个属性会被设置:id、hashString & name。

您还可以添加一些额外的选项,这将覆盖Transmission的默认设置

$torrent = $transmission->torrents()->addFromUrl($urlToTorrent, ['uploadLimit' => 512]);

设置默认值

您还可以全局覆盖Transmission的默认设置

$torrents = $transmission->torrents()->defaults(['uploadLimit' => 512]);

$torrent = $torrents->addFromUrl($urlToTorrent);

种子实体方法

这些是在HappyDemon\Services\Transmission\Torrents\Entity对象上可用的方法。

操作

start

$torrent->start();

启动特定种子。

stop

$torrent->stop();

停止特定种子。

verify

$torrent->verify();

验证特定种子。

reannounce

$torrent->announce();

重新宣布特定种子。

remove

$torrent->remove();

删除特定种子。

move

$torrent->move();

将特定种子移动到您的文件系统中的不同位置。

update

允许您更新一些特定种子设置。

$torrent->settings($properties);

您也可以像这样更新单个种子设置

// remove the download limit
$torrent->setDownloadLimited(false);
// set the bandwidth priority
$torrent->setBandwidthPriority(1);
// set the download limit (in K/s)
$torrent->setDownloadLimit(1024*3);
// Mark files as wanted
// Use an empty array for all files, use an array of ids to be more selective [0,2]
// In this case we only want to download the second file
$torrent->setFilesWanted([1]);
// Mark files as unwanted
// Use an empty array for all files, use an array of ids to be more selective [0,2]
// In this case we don't want to download the first file
$torrent->setFilesUnwanted([0]);
// true if session upload limits are honored
$torrent->setHonorsSessionLimits(true);
// Set a new directory for the torrent's contents
$torrent->setLocation('c:/downloads');
// Set the peer limit (max amount of peer)
$torrent->setPeerLimit(40);
// Set the priority for files to high
// Use en empty array to update priority for all files
// or use the file ids [0,2]
$torrent->setPriorityHigh([]);
// Set the priority for files to low
// Use en empty array to update priority for all files
// or use the file ids [0,2]
$torrent->setPriorityLow(false);
// Set the priority for files to normall
// Use en empty array to update priority for all files
// or use the file ids [0,2]
$torrent->setPriorityNormal(false);
// Set the seed ratio limit
$torrent->setSeedRatioLimit(1.2);
// Set the seed ratio mode
// 0 = global, 1 = see seedRatioLimit, 2 = unlimitted
$torrent->setSeedRatioMode(1);
// Change the upload limit (in K/s)
$torrent->setUploadLimit(512);
// Should the torrent's upload be limitted?
$torrent->setUploadLimited(false);

获取器

实体有很多属性,但我已经添加了一些获取器以方便使用

status

$torrent->status();

将返回种子的状态字符串,而$torrent->status只返回一个数字。

activityDate

$torrent->activityDate();

将返回一个DateTime对象,表示种子上次活动的时间。

addedDate

$torrent->addedDate();

将返回一个DateTime对象,表示种子被添加的日期/时间。

doneDate

$torrent->doneDate();

将返回一个DateTime对象,表示种子完成的时间。

percentDone

$torrent->percentDone();

将返回种子下载完成的百分比,而$torrent->percentDone将返回一个浮点数。