-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
74 lines (69 loc) · 2.06 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
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
73
74
var Downloader = require('./lib/Downloader');
var Parser = require('./lib/Parser');
var DB = require('./lib/DataBase');
var utils = require('./lib/utils');
var request = require('./lib/request');
var URL = require("url");
var fs = require('fs');
var path = require('path');
function noop(){}
function App(root){
utils.mkdirs(root);
process.chdir(root);
var dataBase = new DB("dataBase.json");
var App = new Downloader();
App._db = dataBase;
App.plugin("start",function (url){
return App.spawn().init(url).dataBase(dataBase).execute();
});
App.extend("executes",function (array){
utils.parallel(array,function (url,next){
App.start(url).end(next)
});
return App;
});
App.extend("updates",function (array){
console.time("update");
utils.parallel(array,function (dir,next){
App
.spawn()
.update(dir)
.dataBase(dataBase)
.end(next)
},()=>console.timeEnd("update"));
return App;
});
App.extend("batch",function (from,to,temp){
return Array(to-from+1).fill(from).map(function (v,i){
return temp.replace("*",i+v)
});
});
App.extend("convertEbooks",function (array,format){
console.time("update");
utils.parallel(array,function (dir,next){
App
.spawn()
.convertEbook(dir,format)
.end(next)
},()=>console.timeEnd("update"));
return App;
});
App.extend("deepQuest",function (array,selector){
var Quest = [];
utils.parallel(array,function (url,next){
App.getHTMLContent(url,(data)=>{
var $ = Parser.init(data,url).$;
$(selector).each((i,v)=>{
var href = $(v).attr("href");
Quest.push(URL.resolve(url,href));
});
next();
},next);
},function (){
App.executes(Quest);
});
return App;
});
return App;
}
module.exports = App;