From 6371e82fc0cd42e82fdcdf89a6ccea87c09e34d2 Mon Sep 17 00:00:00 2001 From: SettingDust Date: Wed, 24 Oct 2018 00:15:57 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20bangumi=20eps=20date=20(#942)=20&=20?= =?UTF-8?q?=E8=99=8E=E7=89=99=E7=9B=B4=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + docs/README.md | 4 ++++ router.js | 3 +++ routes/bangumi/subject/ep.js | 3 +-- routes/huya/live.js | 31 +++++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 routes/huya/live.js diff --git a/.gitignore b/.gitignore index e274d3a3b3..21d18f03cb 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ yarn-error.log tmp newrelic_agent.log *.swp +*.iml diff --git a/docs/README.md b/docs/README.md index 5a4612bce6..04a9a75e34 100644 --- a/docs/README.md +++ b/docs/README.md @@ -686,6 +686,10 @@ GitHub 官方也提供了一些 RSS: +### 虎牙直播 + + + ## 音视频 ### bilibili diff --git a/router.js b/router.js index 61902d5454..3b4cebf4af 100644 --- a/router.js +++ b/router.js @@ -265,6 +265,9 @@ router.get('/douyu/room/:id', require('./routes/douyu/room')); // 熊猫直播 router.get('/panda/room/:id', require('./routes/panda/room')); +// 虎牙 +router.get('/huya/live/:id', require('./routes/huya/live')); + // v2ex router.get('/v2ex/topics/:type', require('./routes/v2ex/topics')); diff --git a/routes/bangumi/subject/ep.js b/routes/bangumi/subject/ep.js index d0329a929e..0dfd4d19be 100644 --- a/routes/bangumi/subject/ep.js +++ b/routes/bangumi/subject/ep.js @@ -1,5 +1,4 @@ const axios = require('../../../utils/axios'); -const DateTime = require('luxon').DateTime; module.exports = async (subjectID) => { const url = `https://api.bgm.tv/subject/${subjectID}?responseGroup=large`; @@ -19,7 +18,7 @@ module.exports = async (subjectID) => { item: activeEps.reverse().map((e) => ({ title: `ep.${e.sort} ${e.name_cn}`, description: `ep.${e.sort} ${e.name_cn}

${e.desc.replace(/\n+/g, '
')}

`, - pubDate: DateTime.fromFormat(e.airdate, 'yyyy-L-dd'), + pubDate: new Date(e.airdate).toUTCString(), guid: e.id, link: e.url, })), diff --git a/routes/huya/live.js b/routes/huya/live.js new file mode 100644 index 0000000000..332a62cf9d --- /dev/null +++ b/routes/huya/live.js @@ -0,0 +1,31 @@ +const axios = require('../../utils/axios'); + +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 response = await axios({ + method: 'get', + url: url, + }); + + const data = response.data.response['1'].docs[0]; + + let items = []; + if (data.gameLiveOn) { + items = [ + { + title: `${data.live_intro}`, + pubDate: new Date(data.rec_live_time).toUTCString(), + guid: data.uid, + link: url, + image: data.game_avatarUrl180, + }, + ]; + } + + ctx.state.data = { + title: `${data.game_nick}的虎牙直播`, + link: url, + item: items, + }; +};