-
Notifications
You must be signed in to change notification settings - Fork 127
/
scraper.js
72 lines (63 loc) · 2.04 KB
/
scraper.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
62
63
64
65
66
67
68
69
70
71
72
const async = require("async-q"),
config = require("./config"),
eztv = require("./providers/show/eztv")("EZTV"),
katMovie = require("./providers/movie/kat"),
katShow = require("./providers/show/kat"),
util = require("./util");
/* Start movie scraping from KAT. */
const scrapeKATMovies = () => {
return async.eachSeries(config.movieProviders, (provider) => {
util.setStatus("Scraping " + provider.name);
const katProvider = katMovie(provider.name);
return util.spawn(katProvider.search(provider)).then((response) => {
util.log(provider.name + ": Done.");
return response;
});
});
};
/* Start show scraping from KAT. */
const scrapeKATShows = () => {
return async.eachSeries(config.showProviders, (provider) => {
util.setStatus("Scraping " + provider.name);
const katProvider = katShow(provider.name);
return util.spawn(katProvider.search(provider)).then((response) => {
util.log(provider.name + ": Done.");
return response;
});
});
};
/* Start scraping from EZTV. */
const scrapeEZTV = () => {
util.setStatus("Scraping " + eztv.name);
return util.spawn(eztv.search()).then((response) => {
util.log(eztv.name + ": Done.");
return response;
});
};
module.exports = {
/* Initiate the scraping. */
scrape: () => {
let start_time = new Date();
let scrapers = [];
if(config.scrapers.tv.eztv) scrapers.push(scrapeEZTV);
if(config.scrapers.movies.kat) scrapers.push(scrapeKATMovies);
if(config.scrapers.tv.kat) scrapers.push(scrapeKATShows);
util.resetTemp('.log');
util.setlastUpdate();
if(scrapers.length !== 0) {
async.eachSeries(scrapers, (scraper) => {
return scraper();
}).then((value) => {
return util.setStatus("Idle");
}).catch((err) => {
util.onError("Error while scraping: " + err);
return err;
}).done(() => {
util.setUpdateTime(start_time, new Date());
});
} else {
util.onError("Error while scraping: No scrapers enabled");
return "No scrapers enabled";
}
}
};