-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·35 lines (32 loc) · 1.04 KB
/
index.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
#!/bin/node
const exec = require('child_process').exec
const inquirer = require('inquirer')
const promptsConfig = require('./config/prompts')
const scrapper = require('./modules/scrapper')
const prompts = [promptsConfig.sites, promptsConfig.questions]
const argv = require('minimist')(process.argv.slice(2))
process.stdout.write('\033c')
inquirer.prompt(prompts)
.then(answer => scrapper.getResults(answer.sites, answer.search))
.then(results => inquirer.prompt(promptsConfig.results(results)))
.then(torrentSelected => {
let open = typeof argv.c == 'string' && argv.c || typeof argv.client == 'string' && argv.client
if (!open) {
switch (process.platform) {
case 'linux':
// TO-DO: maybe in some GNU/Linux distribution xdg-open won't work...
open = 'xdg-open'
break
case 'win32':
open = 'start'
break
default:
open = 'open'
break
}
}
exec(`${open} ${torrentSelected.magnetLink}`)
})
.catch(err => {
console.log(err)
})