fix(route): 色花堂 with duplicate magnets (#10327)

* fix(route): 色花堂 with duplicate magnets

* fix typo

* refactor: use WHATWG URL
This commit is contained in:
Ethan Shen 2022-07-26 23:03:38 +08:00 committed by GitHub
parent 5060056b5f
commit 277dae093d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 80 additions and 53 deletions

View File

@ -1443,11 +1443,11 @@ JavDB 有多个备用域名,本路由默认使用永久域名 <https://javdb.c
<Route author="bao1991213" example="/yyets/today" path="/yyets/today" radar="1" rssbud="1"/>
## 色花堂中文论坛
## 色花堂
### 分区帖子
<Route author="qiwihui junfengP" example="/dsndsht23/36/368" path="/dsndsht23/:subforumid?/:type?" supportBT="1" :paramsDesc="['版块 id 或板块名称(见下表), 为空默认高清中文字幕', '类型 id, 可在分区类型过滤后的 URL 中找到']">
<Route author="qiwihui junfengP nczitzk" example="/dsndsht23/36/368" path="/dsndsht23/:subforumid?/:type?" supportBT="1" :paramsDesc="['版块 id 或板块名称(见下表), 为空默认高清中文字幕', '类型 id, 可在分区类型过滤后的 URL 中找到']">
**原创 BT 电影**

View File

@ -1639,11 +1639,11 @@ router.get('/enclavebooks/user/:uid', lazyloadRouteHandler('./routes/enclavebook
router.get('/enclavebooks/collection/:uid', lazyloadRouteHandler('./routes/enclavebooks/collection.js'));
// 色花堂
router.get('/dsndsht23/picture/:subforumid', lazyloadRouteHandler('./routes/dsndsht23/index'));
router.get('/dsndsht23/bt/:subforumid?', lazyloadRouteHandler('./routes/dsndsht23/index'));
router.get('/dsndsht23/:subforumid?/:type?', lazyloadRouteHandler('./routes/dsndsht23/index'));
router.get('/dsndsht23/:subforumid?', lazyloadRouteHandler('./routes/dsndsht23/index'));
router.get('/dsndsht23', lazyloadRouteHandler('./routes/dsndsht23/index'));
// router.get('/dsndsht23/picture/:subforumid', lazyloadRouteHandler('./routes/dsndsht23/index'));
// router.get('/dsndsht23/bt/:subforumid?', lazyloadRouteHandler('./routes/dsndsht23/index'));
// router.get('/dsndsht23/:subforumid?/:type?', lazyloadRouteHandler('./routes/dsndsht23/index'));
// router.get('/dsndsht23/:subforumid?', lazyloadRouteHandler('./routes/dsndsht23/index'));
// router.get('/dsndsht23', lazyloadRouteHandler('./routes/dsndsht23/index'));
// 数英网最新文章
router.get('/digitaling/index', lazyloadRouteHandler('./routes/digitaling/index'));

View File

@ -1,6 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const { parseDate } = require('@/utils/parse-date');
const host = 'https://www.sehuatang.net/';
@ -26,7 +26,7 @@ const forumIdMaps = {
};
module.exports = async (ctx) => {
const subformName = ctx.params.subforumid || 'gqzwzm';
const subformName = ctx.params.subforumid ?? 'gqzwzm';
const subformId = subformName in forumIdMaps ? forumIdMaps[subformName] : subformName;
const typefilter = ctx.params.type ? `&filter=typeid&typeid=${ctx.params.type}` : '';
const link = `${host}forum.php?mod=forumdisplay&orderby=dateline&fid=${subformId}${typefilter}`;
@ -35,9 +35,7 @@ module.exports = async (ctx) => {
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
};
let c;
const response = await got({
method: 'get',
url: link,
const response = await got(link, {
headers,
hooks: {
beforeRedirect: [
@ -57,65 +55,61 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
const list = $('#threadlisttableid tbody[id^=normalthread]')
.slice(0, 25)
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25)
.map(function () {
const info = {
title: '[' + $(this).find('th em a').text() + '] ' + $(this).find('a.xst').text(),
link: $(this).find('a.xst').attr('href'),
date: $(this).find('td.by').find('em span span').attr('title'),
date: $(this).find('td.by').find('em span span').attr('title') || $(this).find('td.by').find('em span').first().text(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
list.map((info) => {
const title = info.title;
const date = info.date;
const itemUrl = host + info.link;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
return ctx.cache.tryGet(itemUrl, async () => {
const response = await got(itemUrl, {
headers,
});
const response = await got.get(itemUrl, { headers });
const $ = cheerio.load(response.data);
const postMessage = $("td[id^='postmessage']").slice(0, 1);
const images = $(postMessage).find('img');
for (let k = 0; k < images.length; k++) {
if (!$(images[k]).attr('file') || $(images[k]).attr('file') === 'undefined') {
$(images[k]).replaceWith('');
} else {
$(images[k]).replaceWith(`<img src="${$(images[k]).attr('file')}" />`);
const $ = cheerio.load(response.data);
const postMessage = $("td[id^='postmessage']").slice(0, 1);
const images = $(postMessage).find('img');
for (let k = 0; k < images.length; k++) {
if (!$(images[k]).attr('file') || $(images[k]).attr('file') === 'undefined') {
$(images[k]).replaceWith('');
} else {
$(images[k]).replaceWith(`<img src="${$(images[k]).attr('file')}" />`);
}
}
}
const description = (postMessage.html() || '抓取原帖失败').replace(/ignore_js_op/g, 'div');
const description = (postMessage.html() || '抓取原帖失败').replace(/ignore_js_op/g, 'div');
const single = {
title,
link: itemUrl,
description,
pubDate: new Date(date).toUTCString(),
};
const magnet = postMessage.find('div.blockcode li').text();
const isMag = magnet.startsWith('magnet');
const torrent = postMessage.find('a[href^=forum\\.php\\?mod\\=attachment]:not([href$=nothumb\\=yes])').attr('href');
const hasEnclosureUrl = isMag || torrent !== undefined;
if (hasEnclosureUrl) {
const enclosureUrl = isMag ? magnet : url.resolve(host, torrent);
const enclosure = {
enclosure_url: enclosureUrl,
enclosure_type: isMag ? 'application/x-bittorrent' : 'application/octet-stream',
const single = {
title,
link: itemUrl,
description,
pubDate: date ? parseDate(date) : null,
};
Object.assign(single, enclosure);
}
if (description !== '抓取原帖失败') {
ctx.cache.set(itemUrl, JSON.stringify(single));
}
return Promise.resolve(single);
const magnet = postMessage.find('div.blockcode li').first().text();
const isMag = magnet.startsWith('magnet');
const torrent = postMessage.find('a[href^=forum\\.php\\?mod\\=attachment]:not([href$=nothumb\\=yes])').attr('href');
const hasEnclosureUrl = isMag || torrent !== undefined;
if (hasEnclosureUrl) {
const enclosureUrl = isMag ? magnet : new URL(torrent, host).href;
const enclosure = {
enclosure_url: enclosureUrl,
enclosure_type: isMag ? 'application/x-bittorrent' : 'application/octet-stream',
};
Object.assign(single, enclosure);
}
return single;
});
})
);

View File

@ -0,0 +1,7 @@
module.exports = {
'/bt/:subforumid?': ['qiwihui', 'junfengP', 'nczitzk'],
'/picture/:subforumid': ['qiwihui', 'junfengP', 'nczitzk'],
'/:subforumid?/:type?': ['qiwihui', 'junfengP', 'nczitzk'],
'/:subforumid?': ['qiwihui', 'junfengP', 'nczitzk'],
'/': ['qiwihui', 'junfengP', 'nczitzk'],
};

19
lib/v2/dsndsht23/radar.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = {
'sehuatang.net': {
_name: '色花堂',
'.': [
{
title: '分区帖子',
docs: 'https://docs.rsshub.app/multimedia.html#se-hua-tang-fen-qu-tie-zi',
source: ['/:category', '/'],
target: (params, url) => {
const theUrl = new URL(url);
const matches = String(theUrl).match(/forum-(\d)+-\d+/);
const fid = theUrl.searchParams.get('fid') || (matches ? matches[1] : '');
const tid = theUrl.searchParams.get('typeid');
return `/dsndsht23${fid ? `/${fid}` : ''}${tid ? `/${tid}` : ''}`;
},
},
],
},
};

View File

@ -0,0 +1,7 @@
module.exports = function (router) {
router.get('/bt/:subforumid?', require('./index'));
router.get('/picture/:subforumid', require('./index'));
router.get('/:subforumid?/:type?', require('./index'));
router.get('/:subforumid?', require('./index'));
router.get('', require('./index'));
};