forked from rafipiccolo/node-rtorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
50 lines (38 loc) · 1.35 KB
/
cli.js
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
#! /usr/bin/env node
var Rtorrent = require('./index.js');
var config = require('./config.json');
var rtorrent = new Rtorrent({
mode: config.mode,
host: config.host,
port: config.port,
path: config.path,
user: config.user,
pass: config.pass
});
if (process.argv.length <= 2) {
console.log('USAGE: node-rtorrent cmd ...');
console.log('');
console.log('Exemples:');
console.log(' node-rtorrent get download_list');
console.log(' node-rtorrent get d.multicall main d.name= d.get_base_path=');
console.log(' node-rtorrent get t.multicall XXXXXXX t.id= t.url=');
console.log(' node-rtorrent get load_start "magnet:?xt=urn:xxxx"');
console.log(' node-rtorrent get load_start "http://xxx/xxx.torrent"');
console.log(' node-rtorrent get execute_capture bash -c "ls -la /"');
console.log(' node-rtorrent execute "ls -la /"');
console.log(' node-rtorrent getAll');
process.exit();
}
var method = process.argv[2];
var cmd = process.argv[3];
var params = process.argv.slice(4);
if (rtorrent[method].length == 1)
rtorrent[method](callback);
else if (rtorrent[method].length == 2)
rtorrent[method](cmd, callback);
else
rtorrent[method](cmd, params, callback);
function callback(err, data) {
if (err) return console.log('err: ', err);
console.log(JSON.stringify(data, null, 4));
}