feat: add 战旗直播支持 (#3215)

This commit is contained in:
cssxsh
2019-10-18 12:12:38 +08:00
committed by DIYgod
parent 692c9d376e
commit ff7caf3dd7
3 changed files with 46 additions and 0 deletions
+6
View File
@@ -43,3 +43,9 @@ pageClass: routes
### 直播间开播
<Route author="SettingDust xyqfer" example="/huya/live/edmunddzhang" path="/huya/live/:id" :paramsDesc="['直播间id或主播名(有一些id是名字,如上)']"/>
## 战旗直播
### 直播间开播
<Route author="cssxsh" example="/zhanqi/room/anime" path="/zhanqi/room/:id" :paramsDesc="['直播间 id, 可在主播直播间页 URL 中找到']"/>
+3
View File
@@ -1822,6 +1822,9 @@ router.get('/watchface/:watch_type?/:list_type?', require('./routes/watchface/up
router.get('/cnu/selected', require('./routes/cnu/selected'));
router.get('/cnu/discovery/:type?/:category?', require('./routes/cnu/discovery'));
// 战旗直播
router.get('/zhanqi/room/:id', require('./routes/zhanqi/room'));
// 酒云网
router.get('/wineyun/:category', require('./routes/wineyun'));
+37
View File
@@ -0,0 +1,37 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const id = ctx.params.id;
const regexp = /(?<=window.oPageConfig.oRoom\s*=\s*)\{.*\}/;
const response = await got({
method: 'get',
url: `https://www.zhanqi.tv/${id}`,
});
const html = response.data;
const strArr = html.split('\n');
const str = strArr.find((str) => regexp.test(str));
// console.log(str.match(regexp)[0]);
const room = JSON.parse(str.match(regexp)[0]);
let item;
if (room.status !== '0') {
item = [
{
title: `开播: ${room.title}`,
// unix时间戳
pubDate: new Date(room.liveTime * 1000).toUTCString(),
guid: room.liveTime,
link: `https://www.zhanqi.tv${room.url}`,
description: room.roomDesc,
},
];
}
ctx.state.data = {
title: `${room.nickname}的战旗直播间`,
link: `https://www.zhanqi.tv${room.url}`,
item: item,
allowEmpty: true,
};
};