forked from mgoodings/patbrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (32 loc) · 1.05 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
36
37
38
39
40
41
42
43
44
const chokidar = require('chokidar')
const RealDebridWatcher = require('./lib/watchers/real-debrid')
const Aria2Downloader = require('./lib/downloaders/aria2')
const {
REAL_DEBRID_API_KEY,
ARIA2_URL,
ARIA2_SECRET,
WATCH_DIR = '/watch',
WATCH_RATE = 5000
} = process.env
if (!REAL_DEBRID_API_KEY) {
console.log('[!] REAL_DEBRID_API_KEY env var is not set')
process.exit(-1)
}
if (!ARIA2_URL) {
console.log('[!] ARIA2_URL env var is not set')
process.exit(-1)
}
if (!ARIA2_SECRET) {
console.log('[!] ARIA2_SECRET env var is not set')
process.exit(-1)
}
// Create a downloader instance
const downloader = new Aria2Downloader(ARIA2_URL, ARIA2_SECRET)
// Create a watcher instance
const watcher = new RealDebridWatcher(REAL_DEBRID_API_KEY, downloader.download)
// Watch for new torrent files
console.log(`[+] Watching '${WATCH_DIR}' for new torrents`)
chokidar.watch(`${WATCH_DIR}/*.torrent`)
.on('add', path => watcher.addTorrent(path))
// Check the torrent watch list every "WATCH_RATE" ms
setInterval(() => watcher.checkWatchList(), WATCH_RATE)