mostertb/transmission-php

kleiram/transmission-php PHP Transmission RPC 客户端库的非维护版本的分支

v1.1.0 2020-04-12 12:03 UTC

This package is auto-updated.

Last update: 2024-09-04 18:27:02 UTC


README

Latest Stable Version Total Downloads License Build Status

此仓库包含非维护的 kleiram/transmission-php PHP Transmission RPC 客户端库的分支。此分支提供了对更新版本的 PHP 和 Transmission 新版本的功能的支持,以及对上游问题的修复。有关更改的完整列表,请参阅 CHANGLOG

此库提供了访问 Transmission BitTorrent 下载器的接口。它提供了从下载器获取和删除种子以及将新的种子添加到下载队列的方法。

安装

使用 Composer 安装非常简单

composer require mostertb/transmission-php

使用

使用库与安装一样简单

<?php
use Transmission\Transmission;

$transmission = new Transmission();

// Getting all the torrents currently in the download queue
$torrents = $transmission->all();

// Getting a specific torrent from the download queue
$torrent = $transmission->get(1);

// (you can also get a torrent by the hash of the torrent)
$torrent = $transmission->get(/* torrent hash */);

// Adding a torrent to the download queue
$torrent = $transmission->add(/* path to torrent */);

// Removing a torrent from the download queue
$torrent = $transmission->get(1);
$transmission->remove($torrent);

// Or if you want to delete all local data too
$transmission->remove($torrent, true);

// You can also get the Trackers that the torrent currently uses
// These are instances of the Transmission\Model\Tracker class
$trackers = $torrent->getTrackers();

// You can also get the Trackers statistics and info that the torrent currently has
// These are instances of the Transmission\Model\trackerStats class
$trackerStats = $torrent->getTrackerStats();

// To get the start date/time of the torrent in UNIX Timestamp format
$startTime = $torrent -> getStartDate();

// To get the number of peers connected
$connectedPeers = $torrent -> getPeersConnected();

// Getting the files downloaded by the torrent are available too
// These are instances of Transmission\Model\File
$files = $torrent->getFiles();

// You can start, stop, verify the torrent and ask the tracker for
// more peers to connect to
$transmission->stop($torrent);
$transmission->start($torrent);
$transmission->start($torrent, true); // Pass true if you want to start the torrent immediatly
$transmission->verify($torrent);
$transmission->reannounce($torrent);

要找出种子包含哪些信息,请查看 Transmission\Model\Torrent

默认情况下,库将尝试连接到 localhost:9091。如果您想连接到其他主机或端口,可以将这些信息传递给 Transmission 类的构造函数。

<?php
use Transmission\Transmission;

$transmission = new Transmission('example.com', 33);

$torrents = $transmission->all();
$torrent  = $transmission->get(1);
$torrent  = $transmission->add(/* path to torrent */);

// When you already have a torrent, you don't have to pass the client again
$torrent->delete();

构造函数还将允许您使用其第三个参数配置非标准 RPC URL,以及使用其第四个参数配置请求超时(以秒为单位)。所有参数都是可选的。

<?php
use Transmission\Transmission;

$transmission = new Transmission(null, null, '/transmission/some-custom-url/rpc', 10);

您还可以直接传递种子数据而不是使用文件,但元数据必须进行 base64 编码。

<?php
$torrent = $transmission->add(/* base64-encoded metainfo */, true);

如果 Transmission 服务器使用用户名和密码进行安全保护,您可以使用 Client 类进行身份验证。

<?php
use Transmission\Client;
use Transmission\Transmission;

$client = new Client(); // Can take the same optional parameters for host, port, url and timeout as the Transmission class
$client->authenticate('username', 'password');
$transmission = new Transmission();
$transmission->setClient($client);

此外,您还可以控制实际的 Transmission 设置。这意味着您可以修改全局下载限制或更改下载目录。

<?php
use Transmission\Transmission;

$transmission = new Transmission();
$session = $transmission->getSession();

$session->setDownloadDir('/home/foo/downloads/complete');
$session->setIncompleteDir('/home/foo/downloads/incomplete');
$session->setIncompleteDirEnabled(true);
$session->save();

测试

测试使用 PHPUnit 完成。假设您的 composer install 包括了开发依赖项,您可以直接从 vendor 目录运行此项目支持的 PHPUnit 版本。

php vendor/bin/phpunit

许可

此库根据 BSD 2-clause 许可证授权。请参阅 LICENSE 文件。