From 73f1a2b8d2dee23d9c8b7071eaf498d12d1facb4 Mon Sep 17 00:00:00 2001 From: SettingDust Date: Tue, 6 Nov 2018 20:12:32 +0800 Subject: [PATCH] Fix the huya (#1074) --- routes/huya/live.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/routes/huya/live.js b/routes/huya/live.js index a0fc0961a..b48ca69b0 100644 --- a/routes/huya/live.js +++ b/routes/huya/live.js @@ -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, }; };