Files
RSSHub/lib/routes/zhanqi/room.js
T
Sukka d82847f541 style/chore(eslint): enforce new rules (#8040)
* style: prefer object shorthand syntax
* refactor: prefer Array#map over Array#forEach
* style: prefer arrow callback
* chore(eslint): update rules
* style: auto fix by eslint
2021-08-17 22:23:23 +08:00

38 lines
1.0 KiB
JavaScript

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,
allowEmpty: true,
};
};