This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sabnzbd_helper.php
64 lines (52 loc) · 1.76 KB
/
sabnzbd_helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// From: http://stackoverflow.com/a/5501447
function formatSizeUnits ( $bytes , $rounding = 0 ) {
if ( $bytes >= 1073741824 ) {
$bytes = number_format ( $bytes / 1073741824 , $rounding ) . ' GB';
} elseif ( $bytes >= 1048576 ) {
$bytes = number_format ( $bytes / 1048576 , $rounding ) . ' MB';
} elseif ( $bytes >= 1024 ) {
$bytes = number_format ( $bytes / 1024 , $rounding ) . ' KB';
} elseif ( $bytes > 1 ) {
$bytes = $bytes . ' B';
} elseif ( $bytes == 1 ) {
$bytes = $bytes . ' B';
} else {
$bytes = 0 . ' B';
}
return $bytes;
}
require_once ( 'config.php' );
$baseSabServer = $sabnzbd['protocol'] . '://' . $sabnzbd['server'] . ':' . $sabnzbd['port'] . '/sabnzbd/';
$ch = curl_init();
curl_setopt ( $ch , CURLOPT_HEADER , 0 );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_URL , $baseSabServer . 'api?apikey=' . $sabnzbd['apikey'] . '&mode=queue&output=json' );
$output = json_decode ( curl_exec ( $ch ) , true );
if ( curl_errno ( $ch ) == 7 ) {
// SABnzbd+ server is down
$finalArray = array (
'current-speed' => '0 KB/s' ,
'status' => 'Offline' ,
'sizeleft' => '0 B' ,
'version' => 'Offline'
);
} else {
$currentSpeed = formatSizeUnits ( $output['queue']['kbpersec'] * 1024 , 1 ) . '/s';
$status = $output['queue']['status'];
//$sizeleft = $output['queue']['sizeleft'];
//$totalsize = $output['queue']['size'];
$remaining = $output['queue']['timeleft'];
$version = $output['queue']['version'];
$finalArray = array (
'current-speed' => $currentSpeed ,
'status' => $status ,
//'sizeleft' => $sizeleft ,
//'totalsize' => $totalsize ,
'remaining' => $remaining,
'version' => $version ,
);
}
curl_close ( $ch );
header ( 'content-type: application/json' );
echo json_encode ( $finalArray );