UNPKG

820 BJavaScriptView Raw
1const { spawn } = require('child_process');
2const { print, l10n } = require('../utils');
3
4module.exports = (thread, config) => {
5 return new Promise((res, rej) => {
6 print.debug('dmhy:downloaders:deluge:thread', thread);
7 print.debug('dmhy:downloaders:deluge:config', config);
8
9 const task = spawn('deluge-console', ['add', thread.link]);
10 print.debug(`start deluge-console on pid ${task.pid}`);
11
12 task.on('close', (code) => {
13 if (code === 0) {
14 print.success(l10n('DOWNLOADER_DL_SUCCESS', { title: thread.title }));
15 } else {
16 print.error(l10n('DOWNLOADER_DL_FAILED', { title: thread.title }));
17 }
18 res();
19 });
20 task.on('error', (error) => {
21 print.error(l10n('DOWNLOADER_START_FAILED', { downloader: 'deluge' }), error);
22 rej(error);
23 });
24 });
25};