-
Notifications
You must be signed in to change notification settings - Fork 79
/
jugg.php
40 lines (39 loc) · 1.19 KB
/
jugg.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
<?php
class Aria2{
protected $ch;
function __construct($server='http://127.0.0.1:6800/jsonrpc'){
$this->ch = curl_init($server);
curl_setopt_array($this->ch, [
CURLOPT_POST=>true,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_HEADER=>false
]);
}
function __destruct(){
curl_close($this->ch);
}
protected function req($data){
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
return curl_exec($this->ch);
}
function __call($name, $arg){
$data = [
'jsonrpc'=>'2.0',
'id'=>'1',
'method'=>'aria2.'.$name,
'params'=>$arg
];
$data = json_encode($data);
$response = $this->req($data);
if($response===false) {
trigger_error(curl_error($this->ch));
}
return json_decode($response, 1);
}
}
$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');
$dir=dirname(__FILE__);
var_dump($aria2->addUri(array('https://www.google.com.hk/images/srpr/logo3w.png'),array(
'dir'=>$dir,
)));
var_dump($aria2->getGlobalStat());