Skip to content

Commit

Permalink
feat(route): add BT之家 (DIYgod#8537)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored Nov 27, 2021
1 parent 56f1469 commit 1501116
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 79 deletions.
44 changes: 43 additions & 1 deletion docs/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,51 @@ pageClass: routes

## BT 之家

### 分类

<Route author="nczitzk" example="/btzj" path="/btzj/:category?" :paramsDesc="['分类,可在对应分类页 URL 中找到,默认为首页']">

::: tip 提示

分类页中域名末尾到 `.htm` 前的字段即为对应分类,如 [电影](https://www.btbtt20.com/forum-index-fid-951.htm) <https://www.btbtt20.com/forum-index-fid-951.htm> 中域名末尾到 `.htm` 前的字段为 `forum-index-fid-951`,所以路由应为 [`/btzj/forum-index-fid-951`](https://rsshub.app/btzj/forum-index-fid-951)

部分分类页,如 [电影](https://www.btbtt20.com/forum-index-fid-951.htm)[剧集](https://www.btbtt20.com/forum-index-fid-950.htm) 等,提供了更复杂的分类筛选。你可以将选项选中后,获得结果分类页 URL 中分类参数,构成路由。如选中分类 [高清电影 - 年份:2021 - 地区:欧美](https://www.btbtt20.com/forum-index-fid-1183-typeid1-0-typeid2-738-typeid3-10086-typeid4-0.htm) <https://www.btbtt20.com/forum-index-fid-1183-typeid1-0-typeid2-738-typeid3-10086-typeid4-0.htm> 中域名末尾到 `.htm` 前的字段为 `forum-index-fid-1183-typeid1-0-typeid2-738-typeid3-10086-typeid4-0`,所以路由应为 [`/btzj/forum-index-fid-1183-typeid1-0-typeid2-738-typeid3-10086-typeid4-0`](https://rsshub.app/btzj/forum-index-fid-1183-typeid1-0-typeid2-738-typeid3-10086-typeid4-0)

:::

基础分类如下:

| 交流 | 电影 | 剧集 | 高清电影 |
| ------------------- | ------------------- | ------------------- | -------------------- |
| forum-index-fid-975 | forum-index-fid-951 | forum-index-fid-950 | forum-index-fid-1183 |

| 音乐 | 动漫 | 游戏 | 综艺 |
| ------------------- | ------------------- | ------------------- | -------------------- |
| forum-index-fid-953 | forum-index-fid-981 | forum-index-fid-955 | forum-index-fid-1106 |

| 图书 | 美图 | 站务 | 科技 |
| -------------------- | ------------------- | ----------------- | ------------------- |
| forum-index-fid-1151 | forum-index-fid-957 | forum-index-fid-2 | forum-index-fid-952 |

| 求助 | 音轨字幕 |
| -------------------- | -------------------- |
| forum-index-fid-1187 | forum-index-fid-1191 |

::: tip 提示

BT 之家的域名会变更,本路由以 <https://www.btbtt20.com> 为默认域名,若该域名无法访问,可以通过在路由后方加上 `?domain=<域名>` 指定路由访问的域名。如指定域名为 <https://www.btbtt15.com>,则在 `/btzj` 后加上 `?domain=btbtt15.com` 即可,此时路由为 [`/btzj?domain=btbtt15.com`](https://rsshub.app/btzj?domain=btbtt15.com)

如果加入了分类参数,直接在分类参数后加入 `?domain=<域名>` 即可。如指定分类 [剧集](https://www.btbtt20.com/forum-index-fid-950.htm) <https://www.btbtt20.com/forum-index-fid-950.htm> 并指定域名为 <https://www.btbtt15.com>,即在 `/btzj/forum-index-fid-950` 后加上 `?domain=btbtt15.com`,此时路由为 [`/btzj/forum-index-fid-950?domain=btbtt15.com`](https://rsshub.app/btzj/forum-index-fid-950?domain=btbtt15.com)

目前,你可以选择的域名有 `btbtt10-20.com` 共 10 个,或 `88btbbt.com`,该站也提供了专用网址查询工具。详见 [此贴](https://www.btbtt20.com/thread-index-fid-2-tid-4550191.htm)

:::

</Route>

### 最新种子

<Route author="zhang-wangz" example="/btzj/base" path="/btzj/:type?" anticrawler="1" :paramsDesc="['type,见下表']">
<Route author="zhang-wangz nczitzk" example="/btzj/base" path="/btzj/:type?" anticrawler="1" :paramsDesc="['type,见下表']">

| base | govern |
| -------------------------- | ------------------------ |
Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ router.get('/dytt', lazyloadRouteHandler('./routes/dytt/index'));
router.get('/dytt/index', lazyloadRouteHandler('./routes/dytt/index')); // 废弃

// BT之家
router.get('/btzj/:type?', lazyloadRouteHandler('./routes/btzj/index'));
// router.get('/btzj/:type?', lazyloadRouteHandler('./routes/btzj/index'));

// 人生05电影网
router.get('/rs05/rs05', lazyloadRouteHandler('./routes/rs05/rs05'));
Expand Down
77 changes: 0 additions & 77 deletions lib/routes/btzj/index.js

This file was deleted.

98 changes: 98 additions & 0 deletions lib/v2/btzj/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
let category = ctx.params.category ?? '';
let domain = ctx.query.domain ?? 'btbtt20.com';

if (category === 'base') {
category = '';
domain = '88btbtt.com';
} else if (category === 'govern') {
category = '';
domain = '2btjia.com';
}

const rootUrl = `https://www.${domain}`;
const currentUrl = `${rootUrl}${category ? `/${category}.htm` : ''}`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

$('.bg2').prevAll('table').remove();

let items = $('#threadlist table')
.toArray()
.map((item) => {
const a = $(item).find('.subject_link');

return {
title: a.text(),
link: `${rootUrl}/${a.attr('href')}`,
};
});

items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});

const content = cheerio.load(detailResponse.data);

content('h2, .message').remove();

content('.attachlist')
.find('a')
.each(function () {
content(this)
.children('img')
.attr('src', `${rootUrl}${content(this).children('img').attr('src')}`);
content(this).attr(
'href',
`${rootUrl}/${content(this)
.attr('href')
.replace(/^attach-dialog/, 'attach-download')}`
);
});

const torrents = content('.attachlist').find('a');

item.description = content('.post').html();
item.author = content('.purple, .grey').first().prev().text();
item.pubDate = timezone(parseDate(content('.bg2 b').first().text()), +8);

if (torrents.length > 0) {
item.description += art(path.join(__dirname, 'templates/torrents.art'), {
torrents: torrents.toArray().map((t) => content(t).parent().html()),
});
item.enclosure_type = 'application/x-bittorrent';
item.enclosure_url = torrents.first().attr('href');
}

return item;
})
)
);

ctx.state.data = {
title: `${$('#menu, #threadtype')
.find('.checked')
.toArray()
.map((c) => $(c).text())
.filter((c) => c !== '全部')
.join('|')} - BT之家`,
link: currentUrl,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/btzj/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/btzj/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'btbtt20.com': {
_name: 'BT之家',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/multimedia.html#bt-zhi-jia',
source: ['/'],
target: '/btzj/:category?',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/btzj/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:category?', require('./index'));
};
5 changes: 5 additions & 0 deletions lib/v2/btzj/templates/torrents.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<table>
{{ each torrents torrent }}
<tr><td>{{ torrent }}</td></tr>
{{ /each }}
</table>

0 comments on commit 1501116

Please sign in to comment.