-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
129 lines (106 loc) · 3.83 KB
/
run.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const axios = require('axios');
const cheerio = require('cheerio');
const fs = require('fs');
const Promise = require('bluebird');
const mkdirp = require('mkdirp');
const util = require('util');
//const theList = 'http://www.r18.com/videos/vod/movies/list/id=45425/pagesize=30/price=all/sort=popular/type=studio/page=';
const theList = 'http://www.r18.com/videos/vod/movies/list/id=2001/pagesize=30/price=all/sort=popular/type=category/page=';
const theListLength = 1654;
//const theListLength = 1;
function genEachPage(theList, theListLength) {
const theReturn = [];
// theList ==== http://www.r18.com/videos/vod/movies/list/id=45425/pagesize=30/price=all/sort=popular/type=studio/page=/
for(var i=1; i<=theListLength; i++) {
let page = theList + i;
theReturn.push(page);
}
return theReturn;
}
function main() {
let pornArr = genEachPage(theList, theListLength);
console.log("total page");
console.log(pornArr);
return Promise.each(pornArr, (page) => {
return new Promise((resolve, reject) => {
axios.get(page)
.then((pageList) => {
console.log("------ working on this list page --------");
console.log(page);
$ = cheerio.load(pageList.data, {xmlMode: false});
let html = $('ul.cmn-list-product01 li a').get();
let individualActorArr = [];
for(var i=0; i<html.length; i++) {
let myhref = html[i].attribs.href;
if(myhref !== undefined) {
individualActorArr.push(myhref);
}
else {
}
}
resolve(individualActorArr);
})
.catch( (error) => {
console.log(error);
});
})
.then((individualActorArr) => {
return Promise.each(individualActorArr, (actorPage) => {
return new Promise((resolve, reject) => {
axios.get(actorPage)
.then((actorPageSource) => {
//console.log(actorPageSource);
$ = cheerio.load(actorPageSource.data, {xmlMode: false});
let html = $('ul.js-owl-carousel li img.lazyOwl').get();
//console.log(html);
let imgSrcArr = [];
for(var i=0; i<html.length; i++) {
let imgSrc = html[i].attribs['data-src'];
//console.log(imgSrc);
let tmpArr = imgSrc.replace("http://pics.r18.com/", "").split("/");
if(tmpArr[3].includes('jp-')){
imgSrcArr.push(imgSrc);
}
else {
continue;
}
}
//console.log(imgSrcArr);
resolve(imgSrcArr);
})
.catch( (error) => {
console.log(error);
});
})
.then((imgSrcArr) => {
//console.log('--------------');
//console.log(imgSrcArr);
return Promise.each(imgSrcArr, (imgUrl) => {
return new Promise((resolve, reject) => {
axios.get(imgUrl, {responseType: 'arraybuffer'})
.then((imgData) => {
// http://pics.r18.com/digital/video/h_237suda00021/h_237suda00021jp-1.jpg
let narr = imgUrl.replace("http://pics.r18.com/", "").split("/");
let savePath = __dirname + "/upload/tmp/" + narr[3];
// https://github.com/mzabriskie/axios/issues/448
fs.writeFile(savePath, imgData.data, "binary", (err) => {
if(err) {
console.log(err);
}
else {
console.log(`save: ${imgUrl}`);
resolve();
}
});
});
});
});
});
});
});
});
}
main().then(() => {
console.log('done');
process.exit(0);
});