forked from yydfys/CatPawOpen
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path13bqg.js
More file actions
235 lines (225 loc) · 7.56 KB
/
13bqg.js
File metadata and controls
235 lines (225 loc) · 7.56 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import req from '../../util/req.js';
import { MOBILE_UA } from '../../util/misc.js';
import { load } from 'cheerio';
let url = 'https://m.13bqg.cc';
async function request(reqUrl) {
let resp = await req.get(reqUrl, {
headers: {
'Accept-Language': 'zh-CN,zh;q=0.8',
'User-Agent': MOBILE_UA,
},
});
return resp.data;
}
async function init(_inReq, _outResp) {
return {};
}
async function home(_inReq, _outResp) {
var html = await request(url);
const $ = load(html);
let classes = [];
for (const a of $('div.nav > ul > li > a[href!="/"]')) {
classes.push({
type_id: a.attribs.href.replace(/\//g, ''),
type_name: a.children[0].data.trim(),
tline: 2,
});
}
return {
class: classes,
};
}
async function category(inReq, _outResp) {
const tid = inReq.body.id;
const pg = inReq.body.page;
let page = pg || 1;
if (page == 0) page = 1;
var html = await request(url + `/${tid}/${page}.html`);
const $ = load(html);
let books = [];
for (const item of $('div.item')) {
const a = $(item).find('a:first')[0];
const img = $(a).find('img:first')[0];
const span = $(item).find('span:first')[0];
books.push({
book_id: a.attribs.href,
book_name: img.attribs.alt,
book_pic: img.attribs.src,
book_remarks: span.children[0].data.trim(),
});
}
return {
page: pg,
pagecount: $('div.page > a:contains(>)').length > 0 ? pg + 1 : pg,
list: books,
};
}
async function detail(inReq, _outResp) {
const ids = !Array.isArray(inReq.body.id) ? [inReq.body.id] : inReq.body.id;
const books = [];
for (const id of ids) {
var html = await request(url + id);
var $ = load(html);
let book = {
book_name: $('[property$=book_name]')[0].attribs.content,
book_year: $('[property$=update_time]')[0].attribs.content,
book_director: $('[property$=author]')[0].attribs.content,
book_content: $('[property$=description]')[0].attribs.content,
};
html = await request(url + id + `list.html`);
$ = load(html);
let urls = [];
const links = $('dl>dd>a[href*="/html/"]');
for (const l of links) {
var name = $(l).text().trim();
var link = l.attribs.href;
urls.push(name + '$' + link);
}
book.volumes = '全卷';
book.urls = urls.join('#');
books.push(book);
}
return {
list: books,
};
}
async function play(inReq, _outResp) {
let id = inReq.body.id;
var content = '';
while (true) {
var html = await request(url + id);
var $ = load(html);
content += $('#chaptercontent')
.html()
.replace(/<br>|请收藏.*?<\/p>/g, '\n')
.trim();
id = $('a.Readpage_down')[0].attribs.href;
if (id.indexOf('_') < 0) break;
}
return {
content: content + '\n\n',
};
}
async function search(inReq, _outResp) {
const wd = inReq.body.wd;
const cook = await req.get(`${url}/user/hm.html?q=${encodeURIComponent(wd)}`, {
headers: {
accept: 'application/json',
'User-Agent': MOBILE_UA,
Referer: `${url}/s?q=${encodeURIComponent(wd)}`,
},
});
const set_cookie = Array.isArray(cook.headers['set-cookie']) ? cook.headers['set-cookie'].join(';;;') : cook.headers['set-cookie'];
const cks = set_cookie.split(';;;');
const cookie = {};
for (const c of cks) {
const tmp = c.trim();
const idx = tmp.indexOf('=');
const k = tmp.substr(0, idx);
const v = tmp.substr(idx + 1, tmp.indexOf(';') - idx - 1);
cookie[k] = v;
}
const resp = await req.get(`${url}/user/search.html?q=${encodeURIComponent(wd)}&so=undefined`, {
headers: {
accept: 'application/json',
'User-Agent': MOBILE_UA,
cookie: 'hm=' + cookie['hm'],
Referer: `${url}/s?q=${encodeURIComponent(wd)}`,
},
});
let books = [];
for (const book of resp.data) {
books.push({
book_id: book.url_list,
book_name: book.articlename,
book_pic: book.url_img,
book_remarks: book.author,
});
}
return {
tline: 2,
list: books,
};
}
async function test(inReq, outResp) {
try {
const printErr = function (json) {
if (json.statusCode && json.statusCode == 500) {
console.error(json);
}
};
const prefix = inReq.server.prefix;
const dataResult = {};
let resp = await inReq.server.inject().post(`${prefix}/init`);
dataResult.init = resp.json();
printErr(resp.json());
resp = await inReq.server.inject().post(`${prefix}/home`);
dataResult.home = resp.json();
printErr(resp.json());
if (dataResult.home.class.length > 0) {
resp = await inReq.server.inject().post(`${prefix}/category`).payload({
id: dataResult.home.class[0].type_id,
page: 1,
filter: true,
filters: {},
});
dataResult.category = resp.json();
printErr(resp.json());
if (dataResult.category.list.length > 0) {
resp = await inReq.server.inject().post(`${prefix}/detail`).payload({
id: dataResult.category.list[0].book_id, // dataResult.category.list.map((v) => v.vod_id),
});
dataResult.detail = resp.json();
printErr(resp.json());
if (dataResult.detail.list && dataResult.detail.list.length > 0) {
dataResult.play = [];
for (const book of dataResult.detail.list) {
const flags = book.volumes.split('$$$');
const ids = book.urls.split('$$$');
for (let j = 0; j < flags.length; j++) {
const flag = flags[j];
const urls = ids[j].split('#');
for (let i = 0; i < urls.length && i < 2; i++) {
resp = await inReq.server
.inject()
.post(`${prefix}/play`)
.payload({
flag: flag,
id: urls[i].split('$')[1],
});
dataResult.play.push(resp.json());
}
}
}
}
}
}
resp = await inReq.server.inject().post(`${prefix}/search`).payload({
wd: '科技',
page: 1,
});
dataResult.search = resp.json();
printErr(resp.json());
return dataResult;
} catch (err) {
console.error(err);
outResp.code(500);
return { err: err.message, tip: 'check debug console output' };
}
}
export default {
meta: {
key: '13bqg',
name: '笔趣阁',
type: 10,
},
api: async (fastify) => {
fastify.post('/init', init);
fastify.post('/home', home);
fastify.post('/category', category);
fastify.post('/detail', detail);
fastify.post('/play', play);
fastify.post('/search', search);
fastify.get('/test', test);
},
};