Skip to content

Commit 5a65477

Browse files
committed
Modify torrents to have supported params.
Add properties method to Torrent. Add info on torrents/info to readme.
1 parent ae1113f commit 5a65477

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ $torrent = $qbt->torrent($hash);
6161
This torrent object may then interact with the torrent API. To get a list of all torrents use the `torrents` method:
6262

6363
```php
64+
// Note: `torrents/info` is implemented in the base qbittorrent class instead of the Torrent class
6465
$torrents = $qbt->torrents();
6566
foreach ($torrents as $torrent_data) {
6667
$torrent = $qbt->torrent($torrent_data->hash);

src/QBittorrent.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,25 @@ public function sync(): Sync {
151151
return $this->cloneApiObject($sync);
152152
}
153153

154-
public function torrents(array $options = []): array {
154+
public function torrents(
155+
?string $filter = null,
156+
?string $category = null,
157+
?string $tag = null,
158+
?string $sort = null,
159+
?bool $reverse = null,
160+
?int $limit = null,
161+
?int $offset = null,
162+
?string $hashes = null
163+
): array {
164+
$options = [];
165+
$ref = new \ReflectionMethod($this, 'torrents');
166+
foreach ($ref->getParameters() as $param) {
167+
$value = ${$param->name};
168+
if (!is_null($value)) {
169+
$options[$param->name] = $value;
170+
}
171+
}
172+
155173
$response = $this->client->get('torrents/info', ['query' => $options]);
156174
$body = $response->getBody();
157175
$data = json_decode($body->getContents());

src/QBittorrent/Torrent.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ public function peers(int $rid = 0): object {
3737
return $this->sync()->torrentPeers($this->getHash(), $rid);
3838
}
3939

40+
public function properties(): object {
41+
$response = $this->client->get($this->prefix . 'files', [
42+
'query' => [
43+
'hash' => $this->hash
44+
]
45+
]);
46+
47+
if ($response->getStatusCode() === 404) {
48+
return (object)[];
49+
}
50+
51+
$body = $response->getBody();
52+
$data = json_decode($body->getContents());
53+
$body->close();
54+
55+
return $data;
56+
}
57+
4058
public function renameFile(string $old_path, string $new_path): ResponseInterface {
4159
return $this->client->post($this->prefix . 'renameFile', [
4260
'form_params' => [

0 commit comments

Comments
 (0)