Skip to content

Commit 8255133

Browse files
authored
Fix-for-Transmission4 (#765)
* Fix-for-Transmission4 * php-cs-fix
1 parent 6a952ea commit 8255133

File tree

1 file changed

+16
-48
lines changed

1 file changed

+16
-48
lines changed

Transmission/Transmission.php

+16-48
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ class Transmission extends \App\SupportedApps implements \App\EnhancedApps
88
public $attrs = [];
99
public $vars;
1010

11-
//protected $login_first = true; // Uncomment if api requests need to be authed first
12-
protected $method = "POST"; // Uncomment if requests to the API should be set by POST
11+
protected $method = "POST";
1312

1413
public function __construct()
1514
{
16-
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
1715
$body["method"] = "torrent-get";
1816
$body["arguments"] = [
1917
"fields" => ["percentDone", "status", "rateDownload", "rateUpload"],
@@ -22,13 +20,13 @@ public function __construct()
2220
"http_errors" => false,
2321
"timeout" => 5,
2422
"body" => json_encode($body),
23+
"verify" => false,
2524
];
2625
}
2726

2827
public function test()
2928
{
3029
$test = $this->sendTest();
31-
3230
echo $test->status;
3331
}
3432

@@ -37,18 +35,18 @@ public function livestats()
3735
$status = "inactive";
3836
$res = $this->sendRequest();
3937
if ($res == null) {
40-
//Log::debug('Transmission connection failed');
4138
return "";
4239
}
4340

4441
$details = json_decode($res->getBody());
4542
if (!isset($details->arguments)) {
46-
//Log::debug('Failed to fetch data from Transmission');
4743
return "";
4844
}
4945

5046
$data = [];
5147

48+
error_log(json_encode($details, JSON_PRETTY_PRINT));
49+
5250
$torrents = $details->arguments->torrents;
5351
$seeding_torrents = 0;
5452
$leeching_torrents = 0;
@@ -69,18 +67,8 @@ public function livestats()
6967
$status = "active";
7068
}
7169

72-
$data["download_rate"] = format_bytes(
73-
$rateDownload,
74-
false,
75-
" <span>",
76-
"/s</span>"
77-
);
78-
$data["upload_rate"] = format_bytes(
79-
$rateUpload,
80-
false,
81-
" <span>",
82-
"/s</span>"
83-
);
70+
$data["download_rate"] = format_bytes($rateDownload, false, " <span>", "/s</span>");
71+
$data["upload_rate"] = format_bytes($rateUpload, false, " <span>", "/s</span>");
8472
$data["seed_count"] = $seeding_torrents;
8573
$data["leech_count"] = $leeching_torrents;
8674

@@ -90,37 +78,21 @@ public function livestats()
9078
private function sendTest()
9179
{
9280
$this->setClientOptions();
93-
$test = parent::appTest(
94-
$this->url("transmission/rpc"),
95-
$this->attrs,
96-
$this->vars
97-
);
81+
$test = parent::appTest($this->url("transmission/rpc"), $this->attrs, $this->vars);
9882
if ($test->code === 409) {
9983
$this->setClientOptions();
100-
$test = parent::appTest(
101-
$this->url("transmission/rpc"),
102-
$this->attrs,
103-
$this->vars
104-
);
84+
$test = parent::appTest($this->url("transmission/rpc"), $this->attrs, $this->vars);
10585
}
10686
return $test;
10787
}
10888

10989
private function sendRequest()
11090
{
11191
$this->setClientOptions();
112-
$res = parent::execute(
113-
$this->url("transmission/rpc"),
114-
$this->attrs,
115-
$this->vars
116-
);
92+
$res = parent::execute($this->url("transmission/rpc"), $this->attrs, $this->vars);
11793
if ($res->getStatusCode() === 409) {
11894
$this->setClientOptions();
119-
$res = parent::execute(
120-
$this->url("transmission/rpc"),
121-
$this->attrs,
122-
$this->vars
123-
);
95+
$res = parent::execute($this->url("transmission/rpc"), $this->attrs, $this->vars);
12496
}
12597
return $res;
12698
}
@@ -134,27 +106,23 @@ private function setClientOptions()
134106
$this->config->password,
135107
"Basic",
136108
],
109+
"verify" => false,
110+
];
111+
} else {
112+
$this->attrs = [
113+
"verify" => false,
137114
];
138115
}
139-
$res = parent::execute(
140-
$this->url("transmission/rpc"),
141-
$this->attrs,
142-
$this->vars
143-
);
116+
$res = parent::execute($this->url("transmission/rpc"), $this->attrs, $this->vars);
144117

145118
try {
146-
//print_r($res);
147119
$xtId = $res->getHeaderLine("X-Transmission-Session-Id");
148120
if ($xtId != null) {
149121
$this->attrs["headers"] = [
150122
"X-Transmission-Session-Id" => $xtId,
151123
];
152-
} else {
153-
//Log::error("Unable to get Transmission session information");
154-
//Log::debug("Status Code: ".$res->getStatusCode());
155124
}
156125
} catch (\GuzzleHttp\Exception\ConnectException $e) {
157-
//Log::error("Failed connection to Transmission");
158126
return false;
159127
}
160128
return true;

0 commit comments

Comments
 (0)