feat(route): add 直播吧滚动新闻 (#7621)

* feat(route): add 直播吧滚动新闻

* refactor: migrate to v2

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
Ethan Shen
2022-02-22 04:28:57 +08:00
committed by GitHub
co-authored by TonyRL
parent fe69819cfc
commit 5a59ec4521
9 changed files with 139 additions and 67 deletions
+7 -1
View File
@@ -885,7 +885,13 @@ pageClass: routes
### 滚动新闻
<Route author="nczitzk" example="/zhibo8/more/nba" path="/zhibo8/more/:caty" :paramsDesc="['分类,可选 `nba` 指 NBA,或 `zuqiu` 指 足球']"/>
<Route author="nczitzk" example="/zhibo8/more/nba" path="/zhibo8/more/:category?" :paramsDesc="['分类,见下表,默认为 NBA']">
| NBA | 足球 | 电竞 | 综合 |
| --- | ----- | -------- | ------ |
| nba | zuqiu | dianjing | zonghe |
</Route>
## 中国灵异网
+4 -4
View File
@@ -1781,10 +1781,10 @@ router.get('/polimi/news/:language?', lazyloadRouteHandler('./routes/polimi/news
// dekudeals
router.get('/dekudeals/:type', lazyloadRouteHandler('./routes/dekudeals'));
// 直播吧
router.get('/zhibo8/forum/:id', lazyloadRouteHandler('./routes/zhibo8/forum'));
router.get('/zhibo8/post/:id', lazyloadRouteHandler('./routes/zhibo8/post'));
router.get('/zhibo8/more/:caty', lazyloadRouteHandler('./routes/zhibo8/more'));
// 直播吧 migrated to v2
// router.get('/zhibo8/forum/:id', lazyloadRouteHandler('./routes/zhibo8/forum'));
// router.get('/zhibo8/post/:id', lazyloadRouteHandler('./routes/zhibo8/post'));
// router.get('/zhibo8/more/:category?', lazyloadRouteHandler('./routes/zhibo8/more'));
// 东方网-上海
router.get('/eastday/sh', lazyloadRouteHandler('./routes/eastday/sh'));
-45
View File
@@ -1,45 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = `https://news.zhibo8.cc/${ctx.params.caty}/more.htm`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('ul.articleList li')
.slice(0, 30)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: `http:${a.attr('href')}`,
pubDate: new Date(item.find('span.postTime').text() + ' GMT+8').toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const res = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(res.data);
item.description = content('div.content').html();
return item;
})
)
);
ctx.state.data = {
title: `${$('span.title_g').text()} - 直播吧`,
link: currentUrl,
item: items,
};
};
@@ -1,5 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const id = ctx.params.id;
@@ -13,7 +15,7 @@ module.exports = async (ctx) => {
const out = await Promise.all(
list
.map(async (index, item) => {
.map(async (_, item) => {
item = $(item);
const title = item.find('td:nth-child(1) > a:nth-child(2)').text();
const author = item.find('td:nth-child(2) cite a').text();
@@ -24,25 +26,15 @@ module.exports = async (ctx) => {
title,
author,
link,
pubDate: new Date(date).toUTCString(),
pubDate: timezone(parseDate(date, 'YYYY-MM-DD HH:mm'), +8),
};
const key = link;
const value = await ctx.cache.get(key);
if (value) {
single.description = value;
} else {
single.description = await ctx.cache.tryGet(link, async () => {
const response = await got.get(link);
const $ = cheerio.load(response.data);
$('.detail_ent img').each(function () {
const $img = $(this);
const src = $img.attr('src');
$img.attr('src', 'https:' + src);
});
single.description = $('.detail_ent').html();
ctx.cache.set(key, single.description);
}
return Promise.resolve(single);
return $('.detail_ent').html();
});
return single;
})
.get()
);
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
'/forum/:id': ['LogicJake'],
'/more/:category?': ['nczitzk'],
'/post/:id': ['LogicJake'],
};
+82
View File
@@ -0,0 +1,82 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const categories = {
nba: 'NBA',
zuqiu: '足球',
dianjing: '电竞',
other: '综合',
};
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'nba';
const rootUrl = 'https://news.zhibo8.cc';
let list,
apiUrl = '',
currentUrl = '',
response;
if (category === 'nba' || category === 'zuqiu') {
currentUrl = `${rootUrl}/${category}/more.htm`;
response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
list = $('ul.articleList li')
.slice(0, 30)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: `http:${a.attr('href')}`,
pubDate: timezone(parseDate(item.find('span.postTime').text()), +8),
};
})
.get();
} else {
currentUrl = `${rootUrl}/${category}`;
apiUrl = `https://api.qiumibao.com/application/app/index.php?_url=/news/${category}List`;
response = await got({
method: 'get',
url: apiUrl,
});
list = response.data.data.list.map((item) => ({
title: item.title,
link: `https:${item.url}`,
pubDate: timezone(parseDate(item.createtime), +8),
}));
}
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const res = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(res.data);
item.description = content('div.content').html();
return item;
})
)
);
ctx.state.data = {
title: `${categories[category]} - 直播吧`,
link: currentUrl,
item: items,
};
};
@@ -26,7 +26,7 @@ module.exports = async (ctx) => {
guid: floor,
};
return Promise.resolve(single);
return single;
})
.get()
);
+27
View File
@@ -0,0 +1,27 @@
module.exports = {
'zhibo8.cc': {
_name: '直播吧',
bbs: [
{
title: '子论坛',
docs: 'https://docs.rsshub.app/bbs.html#zhi-bo-ba',
source: ['/'],
target: (_params, url) => `/zhibo8/forum/${new URL(url).searchParams.get('fid')}`,
},
{
title: '回帖',
docs: 'https://docs.rsshub.app/bbs.html#zhi-bo-ba',
source: ['/'],
target: (_params, url) => `/zhibo8/post/${new URL(url).searchParams.get('tid')}`,
},
],
news: [
{
title: '滚动新闻',
docs: 'https://docs.rsshub.app/bbs.html#zhi-bo-ba',
source: ['/:category'],
target: '/zhibo8/more/:category',
},
],
},
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = (router) => {
router.get('/forum/:id', require('./forum'));
router.get('/more/:category?', require('./more'));
router.get('/post/:id', require('./post'));
};