-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
54 lines (47 loc) · 1.44 KB
/
app.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
51
52
53
54
#!/usr/bin/env node
var optimist = require('optimist');
var torget = require('./torget');
// read in args
var argv = optimist
.usage('Usage: $0 [options] search terms')
.describe('n', 'max number of results to display').default('n', 10)
.alias('p', 'path').describe('p', 'torrent file download path (defaults to name of torrent in current dir)')
.alias('a', 'auto').describe('a', 'automatically download first result in search - i.e. non-interactive mode')
.argv;
// create query
var query = argv._.join(' ').trim();
// if forgot to provide query
if (query === '') {
console.log(optimist.help());
process.exit(1);
}
// non-interactive
if (argv.auto) {
torget.get(query, argv, function(err, filename) {
if (err) {
console.log(err);
process.exit(1);
} else {
console.log('torrent file saved as: ' + filename);
process.exit(0);
}
});
} else {
// interactive mode
torget.interactive(query, argv, function(err, torrent) {
if (err) {
console.log(err);
process.exit(1);
}
// download and save torrent
torget.download(torrent, argv, function(err, filename) {
if (err) {
console.log(err);
process.exit(1);
} else {
console.log('torrent file saved as: ' + filename);
process.exit(0);
}
});
});
}