添加t66y路由 (#339)
* Add 3dm news center. * Modify router name, fix timezone issue. * Add entries in Readme. Add 新京报 * Fix an issue that may not show the content. * Fix an issue that may not show the content. * Add t66y router * Fix cache and time tag * Support all sectors and Add error handler * Reduce post list size * Update README.md * Handle videos * Change feeds limitation * Fix a link bug and add entry to README * Fix a link bug and add entry to README * Fix a link bug and add entry to README * Add error handler * Add error handler * Add error handler * Add error handler * Add error handler
This commit is contained in:
parent
e3e353a610
commit
37d230205b
|
|
@ -170,6 +170,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
|||
- 灵梦御所
|
||||
- 分类
|
||||
- 标签
|
||||
- 草榴
|
||||
|
||||
## 鸣谢
|
||||
|
||||
|
|
|
|||
|
|
@ -1395,3 +1395,23 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
|
|||
路由: `/reimu/tag/:tag`
|
||||
|
||||
参数:tag,标签名,例如: **ntr**, **rbq**, **凌辱**
|
||||
|
||||
## 草榴社区
|
||||
|
||||
举例: [https://rsshub.app/t66y/7](https://rsshub.app/t66y/7)
|
||||
|
||||
路由: `/t66y/:id`
|
||||
|
||||
参数: id,板块 id
|
||||
|
||||
| 亚洲无码原创区 | 亚洲有码原创区 | 欧美原创区 | 动漫原创区 | 国产原创区 |
|
||||
| -------------- | -------------- | ---------- | ---------- | ---------- |
|
||||
| 2 | 15 | 4 | 5 | 25 |
|
||||
|
||||
| 中字原创区 | 转帖交流区 | HTTP 下载区 | 在线成人区 |
|
||||
| ---------- | ---------- | ----------- | ---------- |
|
||||
| 26 | 27 | 21 | 22 |
|
||||
|
||||
| 技术讨论区 | 新时代的我们 | 达盖尔的旗帜 |
|
||||
| ---------- | ------------ | ------------ |
|
||||
| 7 | 8 | 16 |
|
||||
|
|
|
|||
|
|
@ -328,4 +328,7 @@ router.get('/reimu/tag/:tag', require('./routes/reimu/tag'));
|
|||
// 央视新闻
|
||||
router.get('/cctv/:category', require('./routes/cctv/category'));
|
||||
|
||||
// 草榴社区
|
||||
router.get('/t66y/:id', require('./routes/t66y/index'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,126 @@
|
|||
const cheerio = require('cheerio');
|
||||
const config = require('../../config');
|
||||
const axios = require('../../utils/axios');
|
||||
const iconv = require('iconv-lite');
|
||||
const url = require('url');
|
||||
|
||||
const base = 'http://www.t66y.com';
|
||||
const section = 'thread0806.php?fid=';
|
||||
const axios_ins = axios.create({
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
Referer: base,
|
||||
},
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
const sourceTimezoneOffset = -8;
|
||||
module.exports = async (ctx) => {
|
||||
const res = await axios_ins.get(url.resolve(base, `${section}${ctx.params.id}`));
|
||||
const data = iconv.decode(res.data, 'gbk');
|
||||
const $ = cheerio.load(data);
|
||||
let list = $('#ajaxtable > tbody:nth-child(2)');
|
||||
list = $('.tr2', list)
|
||||
.not('.tr2.tac')
|
||||
.nextAll();
|
||||
|
||||
const reqList = [];
|
||||
const out = [];
|
||||
const indexList = []; // New item index
|
||||
|
||||
for (let i = 0; i < Math.min(list.length, 20); i++) {
|
||||
const $ = cheerio.load(list[i]);
|
||||
let title = $('.tal h3 a');
|
||||
const path = title.attr('href');
|
||||
const link = url.resolve(base, path);
|
||||
|
||||
// Check cache
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
out.push(JSON.parse(cache));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
cheerio
|
||||
.load(title)('font')
|
||||
.text() !== ''
|
||||
) {
|
||||
title = cheerio
|
||||
.load(title)('font')
|
||||
.text();
|
||||
} else {
|
||||
title = title.text();
|
||||
}
|
||||
|
||||
const single = {
|
||||
title: title,
|
||||
link: link,
|
||||
guid: path,
|
||||
};
|
||||
const promise = axios_ins.get(url.resolve(base, path));
|
||||
reqList.push(promise);
|
||||
indexList.push(i);
|
||||
out.push(single);
|
||||
}
|
||||
let resList;
|
||||
try {
|
||||
resList = await axios.all(reqList);
|
||||
} catch (error) {
|
||||
ctx.state.data = `Error occurred: ${error}`;
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < resList.length; i++) {
|
||||
let item = resList[i];
|
||||
item = iconv.decode(item.data, 'gbk');
|
||||
let $ = cheerio.load(item);
|
||||
let time = $('#main > div:nth-child(4) > table > tbody > tr:nth-child(2) > th > div').text();
|
||||
const regex = /\d{4}-\d{2}-\d{2} \d{2}:\d{2}/;
|
||||
const regRes = regex.exec(time);
|
||||
time = regRes === null ? new Date() : new Date(regRes[0]);
|
||||
time.setTime(time.getTime() + (sourceTimezoneOffset - time.getTimezoneOffset() / 60) * 60 * 60 * 1000);
|
||||
|
||||
const content = $('#main > div:nth-child(4) > table > tbody > tr.tr1.do_not_catch > th:nth-child(2) > table > tbody > tr > td > div.tpc_content.do_not_catch').html();
|
||||
|
||||
// Change the image tag to display image in rss reader
|
||||
try {
|
||||
$ = cheerio.load(content);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle video
|
||||
const video = $('a:nth-of-type(2)');
|
||||
if (video) {
|
||||
const videoScript = video.attr('onclick');
|
||||
const regVideo = /https?:\/\/.*'/;
|
||||
const videoRes = regVideo.exec(videoScript);
|
||||
if (videoRes && videoRes.length !== 0) {
|
||||
let link = videoRes[0];
|
||||
link = link.slice(0, link.length - 1);
|
||||
$('iframe').attr('src', link);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle img tag
|
||||
let images = $('img');
|
||||
for (let k = 0; k < images.length; k++) {
|
||||
$(images[k]).replaceWith(`<img src="${$(images[k]).attr('data-src')}">`);
|
||||
}
|
||||
// Handle input tag
|
||||
images = $('input');
|
||||
for (let k = 0; k < images.length; k++) {
|
||||
$(images[k]).replaceWith(`<img src="${$(images[k]).attr('data-src')}">`);
|
||||
}
|
||||
out[indexList[i]].description = $.html();
|
||||
out[indexList[i]].pubDate = time.toUTCString();
|
||||
ctx.cache.set(out[indexList[i]].link, JSON.stringify(out[indexList[i]]), 3 * 60 * 60);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: url.resolve(base, `${section}${ctx.params.id}`),
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue