-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscraper_manager.js
More file actions
41 lines (36 loc) · 1 KB
/
scraper_manager.js
File metadata and controls
41 lines (36 loc) · 1 KB
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
const LimeTorrents = require('./scrapers/lime_torrents');
const loadScraper = (type) => {
switch (type) {
case 'LimeTorrents':
return LimeTorrents;
default:
throw Error(`Scraper with type ${type} doesn't exist.`);
}
};
let ScraperManager = function (config) {
this._scrapers = {};
for (let i = 0; i < config.length; i++) {
const node = config[i];
const scraperClass = loadScraper(node.type);
this._scrapers[node.id] = new scraperClass(node);
}
};
ScraperManager.prototype = {
initialize: function () {
return Promise.all(Object.values(this._scrapers).map((s) => s.init()));
},
ready: function () {
return Object.values(this._scrapers).every((v) => v._initialized);
},
update: function () {
const keys = Object.keys(this._scrapers);
for (let i = 0; i < keys.length; i++) {
const scraper = this._scrapers[keys[i]];
scraper.update();
}
},
getScraper: function (id) {
return this._scrapers[id];
}
};
module.exports = ScraperManager;