-
Notifications
You must be signed in to change notification settings - Fork 7
/
cli.js
61 lines (53 loc) · 1.6 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
51
52
53
54
55
56
57
58
59
60
61
const program = require("commander")
const fs = require("fs")
const config = require("./config")
const logger = require("./logger")
const QbtAPI = require("./qbtAPI")
const FeedsProcessor = require("./feedsProcessor")
program
.version("0.1.0", "-v, --version")
.description(
"Command line tool to automate torrent download for qBittorrent from an RSS source, to a customizable save paths"
)
program
.command("qbtversion")
.description("Gets the qBittorrent version.")
.action(() => {
logger.info("Getting qBt version")
this.qbtAPI = new QbtAPI()
let result = this.qbtAPI
.getVersion()
.then(res => {
console.log(res)
})
.catch(err => {
logger.error("Error getting version.", err)
})
})
program
.command("fetch")
.option("-f, --feeds <feedsFilePath>")
.description("Fetch the torrents from the feeds defined in the 'feeds' file.")
.action(cmd => {
logger.info("Fetch started")
let feedsFilePath = cmd.feeds || config.feeds_file
// check that the file path is not empty
if (typeof feedsFilePath === "undefined" || feedsFilePath == "") {
logger.error("Feeds file not specified.")
return
}
try {
// check the file existence
fs.statSync(feedsFilePath)
// process the file
let feedsProcessor = new FeedsProcessor()
feedsProcessor.fetch(feedsFilePath)
} catch (err) {
if (err.code === "ENOENT") {
logger.error(`The Feeds file ("${feedsFilePath}") does not exist.`)
} else {
logger.error("Error: " + err)
}
}
})
program.parse(process.argv)