aldobarr / qbittorrent-php
qbittorrent WebUI API 的非官方 PHP 客户端
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.5
This package is auto-updated.
Last update: 2024-09-12 22:47:38 UTC
README
qbittorrent WebUI API 的 PHP 客户端
需求
- PHP 8.1 或更高版本
安装
请使用 Composer 进行安装。有关 Composer 文档,请参阅 getcomposer.org。
安装模块
$ composer require aldobarr/qbittorrent-php
基本用法
基本用法将指示如何使用登录凭据创建新的 API 对象并向 API 发送原始请求。使用此对象的所有请求都将保持登录状态。原始请求方法将返回 PSR-7 ResponseInterface 对象。请参阅 guzzle 文档。
<?php require 'vendor/autoload.php'; use AldoBarr\QBittorrent; $host = 'http://hostname'; $port = 1234; $username = 'admin'; $password = 'pass'; $qbt = new QBittorrent($host, $port, $username, $password); $response = $qbt->request('app/version'); echo $response->getBody()->getContents();
使用
qbittorrent 对象允许您为与不同 API 交互创建更具体的 API 包装器。例如,上面的基本用法示例可以重写为以下内容
echo $qbt->application()->version();
application
方法将返回一个 Application 对象,它扩展了主要的 QBittorrent 对象并保持当前的登录状态。每个实现 api 前缀的子对象都应该包含支持该前缀下每个 api 方法的相应方法。
要访问种子,您可以从 qbt 对象请求种子对象
$hash = 'torrent-hash'; $torrent = $qbt->torrent($hash);
然后,此种子对象可以与种子 API 交互。要获取所有种子的列表,请使用 torrents
方法
// Note: `torrents/info` is implemented in the base qbittorrent class instead of the Torrent class $torrents = $qbt->torrents(); foreach ($torrents as $torrent_data) { $torrent = $qbt->torrent($torrent_data->hash); // Get torrent files print_r($torrent->files()); }
有关可用 API 方法的更多信息,请参阅主要的 QBittorrent WebUI Api 文档。
添加新的种子
要添加新的种子,请使用 QBittorrent 类的 addTorrent
方法。此类支持所有 已记录 的参数。所有参数都是可选的,但是,如果 $urls
和 $file_paths
都为空,则该方法将立即返回 false。$urls
和 $file_paths
都接受用于添加种子的值数组。$file_paths
参数接受一个路径数组,尝试将二进制文件数据发送到 qbittorrent api。$file_paths
还可以是一个可选的键 => 值对,其中键是要指定的文件名称。
$qbt = new QBittorrent(...); $qbt->addTorrent(file_paths: [ 'files1.torrent' => '/home/user/files1.torrent', 'files2.torrent' => '/home/user2/some/path/files2.torrent' ]);
许可证
此 PHP API 包装器是开源软件,根据 GNU 通用公共许可证版本 3 许可。