feat: add 2048 torrent support (#3969)

This commit is contained in:
hoilc 2020-02-15 21:34:18 +08:00 committed by GitHub
parent 48b27fe811
commit a2b6a28105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -8,7 +8,7 @@ pageClass: routes
### 论坛更新
<Route author="hoilc" example="/2048/bbs/16" path="/2048/bbs/:fid" :paramsDesc="['板块 ID, 可在 URL 中找到, 例如, `thread.php?fid-16.html`中, 板块 ID 为`16`']"/>
<Route author="hoilc" example="/2048/bbs/16" path="/2048/bbs/:fid" :paramsDesc="['板块 ID, 可在 URL 中找到, 例如, `thread.php?fid-16.html`中, 板块 ID 为`16`']" supportBT="1" />
## 60-Second Science - Scientific American

View File

@ -37,16 +37,34 @@ module.exports = async (ctx) => {
.text()
.replace(/»/g, '-');
const parseContent = (htmlString) => {
const parseContent = async (htmlString) => {
const $ = cheerio.load(htmlString);
const time = $('.tiptop.cc > .fl.gray').attr('title');
const content = $('.tpc_content');
return {
const result = {
description: content.html(),
pubDate: time ? new Date(time) : new Date(),
};
const test_external_torrent = content.find('a').filter(function() {
return $(this)
.attr('href')
.match(/\/list\.php\?name=\w{32}/);
});
if (test_external_torrent.length !== 0) {
const torrent_url = test_external_torrent[0].attribs.href;
const response = await got.get(torrent_url);
const magnet_url = response.data.match(/"(magnet:\?.*?)"/);
if (magnet_url) {
result.enclosure_url = magnet_url[1];
result.enclosure_type = 'application/x-bittorrent';
}
}
return result;
};
const out = await Promise.all(
@ -86,10 +104,12 @@ module.exports = async (ctx) => {
try {
const response = await got.get(link);
const result = parseContent(response.data);
const result = await parseContent(response.data);
rssitem.description = result.description;
rssitem.pubDate = result.pubDate;
rssitem.enclosure_url = result.enclosure_url;
rssitem.enclosure_type = result.enclosure_type;
} catch (err) {
return Promise.resolve('');
}