feat: add bahamut creation (#3532)
This commit is contained in:
parent
9d8ccd844d
commit
67009c8cb4
|
|
@ -410,6 +410,32 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
|
|||
|
||||
<Route author="HenryQW" example="/youtube/playlist/PLqQ1RwlxOgeLTJ1f3fNMSwhjVgaWKo_9Z" path="/youtube/playlist/:id/:disableEmbed?" :paramsDesc="['播放列表 id', '默认为开启内嵌视频, 任意值为关闭']" radar="1"/>
|
||||
|
||||
## 巴哈姆特
|
||||
|
||||
### 个人小屋
|
||||
|
||||
<Route author="hoilc" example="/bahamut/creation/tpesamguo/338592" path="/bahamut/creation/:author/:category?" :paramsDesc="['作者 ID, 即为个人小屋 URL 中 `owner` 参数','分类ID, 即为创作分类 URL 中 `c` 参数']"/>
|
||||
|
||||
### 创作大厅
|
||||
|
||||
<Route author="hoilc" example="/bahamut/creation_index/4/0/2" path="/bahamut/creation_index/:category?/:subcategory?/:type?" :paramsDesc="['分类 ID, 即为 URL 中 `k1` 参数, 0 或置空为不限','子分类 ID, 即为 URL 中 `k2` 参数, 0或置空为不限', '排行类型, 即为 URL 中 `vt` 参数, 0或置空为達人專欄']">
|
||||
|
||||
分类 ID 参考如下
|
||||
|
||||
| 不限 | 日誌 | 小說 | 繪圖 | Cosplay | 同人商品 |
|
||||
| ---- | ---- | ---- | ---- | ------- | -------- |
|
||||
| 0 | 1 | 2 | 3 | 4 | 5 |
|
||||
|
||||
子分类 ID 比较多不作列举
|
||||
|
||||
排行类型参考如下
|
||||
|
||||
| 達人專欄 | 最新創作 | 最新推薦 | 熱門創作 | 精選閣樓 |
|
||||
| -------- | -------- | -------- | -------- | -------- |
|
||||
| 1 | 2 | 3 | 4 | 5 |
|
||||
|
||||
</Route>
|
||||
|
||||
## 币乎
|
||||
|
||||
### 用户动态
|
||||
|
|
|
|||
|
|
@ -2013,6 +2013,10 @@ router.get('/nyaa/search/:query?', require('./routes/nyaa/search'));
|
|||
// 片源网
|
||||
router.get('/pianyuan/:media?', require('./routes/pianyuan/app'));
|
||||
|
||||
// 巴哈姆特
|
||||
router.get('/bahamut/creation/:author/:category?', require('./routes/bahamut/creation'));
|
||||
router.get('/bahamut/creation_index/:category?/:subcategory?/:type?', require('./routes/bahamut/creation_index'));
|
||||
|
||||
// CentBrowser
|
||||
router.get('/centbrowser/history', require('./routes/centbrowser/history'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const author = ctx.params.author;
|
||||
|
||||
const url = ctx.params.category ? `https://home.gamer.com.tw/creationCategory.php?owner=${author}&c=${ctx.params.category}` : `https://home.gamer.com.tw/creation.php?owner=${author}`;
|
||||
|
||||
const { title, items } = await utils.ProcessFeed(url, ctx);
|
||||
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
const utils = require('./utils');
|
||||
|
||||
const type_map = {
|
||||
0: '達人專欄',
|
||||
1: '達人專欄',
|
||||
2: '最新創作',
|
||||
3: '最新推薦',
|
||||
4: '熱門創作',
|
||||
5: '精選閣樓',
|
||||
};
|
||||
|
||||
const category_map = {
|
||||
0: '不限',
|
||||
1: '日誌',
|
||||
2: '小說',
|
||||
3: '繪圖',
|
||||
4: 'Cosplay',
|
||||
5: '同人商品',
|
||||
};
|
||||
|
||||
const subcategory_map = {
|
||||
0: '不限',
|
||||
1: 'ACG相關',
|
||||
2: '生活休閒',
|
||||
3: '巴哈相關',
|
||||
4: '歡樂惡搞',
|
||||
5: '心情日記',
|
||||
6: '模型/公仔',
|
||||
7: '視聽娛樂',
|
||||
8: '興趣嗜好',
|
||||
9: '其他',
|
||||
10: '愛情',
|
||||
11: '奇幻',
|
||||
12: '科幻',
|
||||
13: '武俠',
|
||||
14: '推理驚悚',
|
||||
15: '歡樂惡搞',
|
||||
16: 'BL/GL',
|
||||
17: '輕小說',
|
||||
18: '其他',
|
||||
19: '紙上塗鴉',
|
||||
20: '草稿/線稿',
|
||||
21: '單色人物',
|
||||
22: '彩色人物',
|
||||
23: '完稿作品',
|
||||
24: '漫畫',
|
||||
25: '勇者造型',
|
||||
26: '其他',
|
||||
27: 'ACG相關',
|
||||
28: '特攝',
|
||||
29: '布袋戲',
|
||||
30: '電影',
|
||||
31: '其他',
|
||||
32: '男性向',
|
||||
33: '女性向',
|
||||
34: '其他',
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type ? ctx.params.type : '1';
|
||||
const category = ctx.params.category ? ctx.params.category : '0';
|
||||
const subcategory = ctx.params.subcategory ? ctx.params.subcategory : '0';
|
||||
|
||||
const url = `https://home.gamer.com.tw/index.php?k1=${category}&k2=${subcategory}&vt=${type}&sm=3`;
|
||||
|
||||
const { items } = await utils.ProcessFeed(url, ctx);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `巴哈姆特创作大厅${category !== '0' ? ' - ' + category_map[category] : ''}${subcategory !== '0' ? ' - ' + subcategory_map[subcategory] : ''} - ${type_map[type]}`,
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const base = 'https://home.gamer.com.tw/';
|
||||
|
||||
module.exports = {
|
||||
ProcessFeed: async (url, ctx) => {
|
||||
const response = await got.get(url);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const title = $('title').text();
|
||||
const list = $('.BH-lbox > .HOME-mainbox1').toArray();
|
||||
|
||||
const parseContent = (htmlString) => {
|
||||
const $ = cheerio.load(htmlString);
|
||||
const content = $('.MSG-list8C');
|
||||
|
||||
const images = $('img');
|
||||
for (let k = 0; k < images.length; k++) {
|
||||
$(images[k]).attr('src', $(images[k]).attr('data-src'));
|
||||
}
|
||||
|
||||
return {
|
||||
description: content.html(),
|
||||
};
|
||||
};
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const title = $('.HOME-mainbox1b > h1 > a');
|
||||
const link = base + title.attr('href');
|
||||
const author = $('.HOME-mainbox1b > .ST1 > a').text();
|
||||
const time = $('.HOME-mainbox1b > .ST1')
|
||||
.text()
|
||||
.split('│')[1];
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const topic = {
|
||||
title: title.text().trim(),
|
||||
link: link,
|
||||
author: author,
|
||||
pubDate: new Date(time),
|
||||
};
|
||||
|
||||
try {
|
||||
const detail_response = await got.get(link);
|
||||
const result = parseContent(detail_response.data);
|
||||
if (!result.description) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
topic.description = result.description;
|
||||
} catch (err) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
ctx.cache.set(link, JSON.stringify(topic));
|
||||
return Promise.resolve(topic);
|
||||
})
|
||||
);
|
||||
|
||||
return { title: title, items: items };
|
||||
},
|
||||
};
|
||||
Loading…
Reference in New Issue