Get a list of torrent statuses via json rpc using php and curl.
Posted: Thu Jan 19, 2017 11:09 am
I have the following code which seems to authorized successfully as I get session back, but then i try and call the get_torrents_status and I get 500 error, I have run daemon with -L option but the log is no help. Can you help advise on how to get a list of torrents statuses in php, have searched everywhere and no joy.
This is the debug info I output to the browser:
Code: Select all
public function deluge_auth($deluge_url, $deluge_password) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $deluge_url);
curl_setopt($curl, CURLOPT_POSTFIELDS, '{"method": "auth.login", "params": ["'.$deluge_password.'"], "id": 1}');
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
$data = curl_exec($curl);
curl_close($curl);
preg_match_all('|Set-Cookie: (.*);|U', $data, $matches);
$cookies = implode('; ', $matches[1]);
return $cookies;
}
public function data_widget_torrents($node) {
$deluge_url = $node->field_deluge_url->value . 'json';
$deluge_password = $node->field_deluge_password->value;
$rpc_call = 'core.get_torrents_status';
$cookies = $this->deluge_auth($deluge_url, $deluge_password);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $deluge_url);
curl_setopt($curl, CURLOPT_POSTFIELDS, '{"method":"' . $rpc_call . '"}');
curl_setopt($curl, CURLOPT_COOKIE, $cookies);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
$data = curl_exec($curl);
curl_close($curl);
p($data);
}
Code: Select all
http://myserver.com:8112/json
core.get_torrents_status
_session_id=51b2a09f63d847be1705d1cc88c9c4762201
HTTP/1.1 500 Internal Server Error
Date: Thu, 19 Jan 2017 11:05:26 GMT
Content-Length: 0
Content-Type: text/html
Server: TwistedWeb/14.0.2