Fix the huya (#1074)
This commit is contained in:
parent
11fd01f653
commit
73f1a2b8d2
|
|
@ -1,31 +1,33 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const url = `https://search.cdn.huya.com/?m=Search&do=getSearchContent&q=${id}&typ=-5&rows=1`;
|
||||
const url = `https://huya.com/${id}`;
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
});
|
||||
|
||||
const data = response.data.response['1'].docs[0];
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = [];
|
||||
if (data.gameLiveOn) {
|
||||
items = [
|
||||
const timestamp = parseInt(response.data.match(/"startTime":(\d+)/)[1]);
|
||||
|
||||
let item;
|
||||
if (response.data.match(/"isOn":(\w{4})/)[1] === 'true') {
|
||||
item = [
|
||||
{
|
||||
title: `${data.live_intro}`,
|
||||
pubDate: new Date(data.rec_live_time * 1000).toUTCString(),
|
||||
guid: data.uid,
|
||||
link: data.game_liveLink,
|
||||
image: data.game_avatarUrl180,
|
||||
title: $('#J_roomTitle').text(),
|
||||
guid: timestamp,
|
||||
pubDate: new Date(timestamp).toUTCString(),
|
||||
link: url,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${data.game_nick}的虎牙直播`,
|
||||
link: `https://huya.com/${id}`,
|
||||
item: items,
|
||||
title: `${$('.host-name').text()}的虎牙直播`,
|
||||
link: url,
|
||||
item: item,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue