From 3f6a573151a3d55ee776319ccf9764228df70094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B1=E7=BA=A2?= <948931744@qq.com> Date: Sun, 1 Jul 2018 23:34:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B1=B3=E5=93=88=E6=B8=B8?= =?UTF-8?q?=EF=BC=8C=E7=81=B5=E6=A2=A6=E5=BE=A1=E6=89=80=20RSS=20(#324)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * rss: add mihoyo * rss: add reimu * modify docs readme --- README.md | 6 +++++ docs/README.md | 52 +++++++++++++++++++++++++++++++++++++++- router.js | 7 ++++++ routes/mihoyo/bh2.js | 45 ++++++++++++++++++++++++++++++++++ routes/mihoyo/bh3.js | 51 +++++++++++++++++++++++++++++++++++++++ routes/reimu/category.js | 37 ++++++++++++++++++++++++++++ routes/reimu/tag.js | 31 ++++++++++++++++++++++++ routes/reimu/util.js | 24 +++++++++++++++++++ 8 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 routes/mihoyo/bh2.js create mode 100644 routes/mihoyo/bh3.js create mode 100644 routes/reimu/category.js create mode 100644 routes/reimu/tag.js create mode 100644 routes/reimu/util.js diff --git a/README.md b/README.md index 570a5fa86..e90b50c26 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,12 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 大连市 - MIUI - 更新 +- 米哈游 + - 崩坏 2-游戏公告 + - 崩坏 3-游戏公告 +- 灵梦御所 + - 分类 + - 标签 ## 鸣谢 diff --git a/docs/README.md b/docs/README.md index 074745e95..0b64d918a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1318,7 +1318,9 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 参数: 无 -### MIUI 更新 +## MIUI + +### 更新 举例: [https://rsshub.app/miui/aries/](https://rsshub.app/miui/aries/) @@ -1337,3 +1339,51 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 | 稳定版 | 开发版 | | ------- | ------ | | release | dev | + +## 米哈游 + +### 崩坏 2-游戏公告 + +举例: [https://rsshub.app/mihoyo/bh2/gach](https://rsshub.app//mihoyo/bh2/gach) + +路由: `/mihoyo/bh2/:type` + +参数:type,公告种类 + +| 最新公告 | 版本信息 | 祈愿信息 | 活动介绍 | +| -------- | -------- | -------- | -------- | +| new | version | gach | event | + +### 崩坏 3-游戏公告 + +举例: [https://rsshub.app/mihoyo/bh3/strategy](https://rsshub.app//mihoyo/bh3/strategy) + +路由: `/mihoyo/bh3/:type` + +参数:type,公告种类 + +| 最新 | 公告 | 新闻 | 活动 | 攻略 | +| ------ | ------ | ---- | -------- | -------- | +| latest | notice | news | activity | strategy | + +## 灵梦御所 + +### 分类 + +举例: [https://rsshub.app/reimu/category/music](https://rsshub.app/reimu/category/music) + +路由: `/reimu/category/:category` + +参数:category,分类名 + +| 3d | 动画 | 合集 | 图包 | 壁纸 | 御所汉化 | 游戏 | 漫画 | 独立 | 表番推荐 | 音声 | +| --- | ----- | ---------- | ------- | --------- | -------- | ---- | ----- | ----- | --------- | ----- | +| 3d | anime | collection | picture | wallpaper | chinese | game | comic | indie | recommend | music | + +### 标签 + +举例: [https://rsshub.app/reimu/tag/ntr](https://rsshub.app/reimu/tag/ntr) + +路由: `/reimu/tag/:tag` + +参数:tag,标签名,例如: **ntr**, **rbq**, **凌辱** diff --git a/router.js b/router.js index 6818ac8b7..ff16da646 100644 --- a/router.js +++ b/router.js @@ -317,6 +317,13 @@ router.get('/tingshuitz/dalian', require('./routes/tingshuitz/dalian')); // MIUI 更新 router.get('/miui/:device/:type?', require('./routes/miui/index')); +// 米哈游 +router.get('/mihoyo/bh3/:type', require('./routes/mihoyo/bh3')); +router.get('/mihoyo/bh2/:type', require('./routes/mihoyo/bh2')); + +// 灵梦御所 +router.get('/reimu/category/:category', require('./routes/reimu/category')); +router.get('/reimu/tag/:tag', require('./routes/reimu/tag')); // 央视新闻 router.get('/cctv/:category', require('./routes/cctv/category')); diff --git a/routes/mihoyo/bh2.js b/routes/mihoyo/bh2.js new file mode 100644 index 000000000..161c37ad0 --- /dev/null +++ b/routes/mihoyo/bh2.js @@ -0,0 +1,45 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const url = 'http://www.mihoyo.com/news/getNotice'; + let type = ctx.params.type; + + const typeArr = ['new', 'version', 'gach', 'event']; + + if (typeArr.indexOf(type) === -1) { + type = typeArr[0]; + } + + const index = typeArr.indexOf(type) + 1 || 1; + + const response = await axios({ + method: 'post', + url: url, + headers: { + 'User-Agent': config.ua, + Referer: url, + 'x-requested-with': 'XMLHttpRequest', + }, + }); + + const data = response.data.data[type] || []; + + const title = `崩坏2-${type}`; + + ctx.state.data = { + title: title, + link: 'http://www.mihoyo.com/news', + description: title, + item: data.map((item) => { + const pubDate = new Date(item.time); + pubDate.setTime(pubDate.getTime() + 8 * 60 * 60 * 1000); + return { + title: item.title, + description: item.title, + pubDate: pubDate.toUTCString(), + link: `http://www.mihoyo.com/news?para=${index}_${item.id}`, + }; + }), + }; +}; diff --git a/routes/mihoyo/bh3.js b/routes/mihoyo/bh3.js new file mode 100644 index 000000000..c0f6bf585 --- /dev/null +++ b/routes/mihoyo/bh3.js @@ -0,0 +1,51 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const url = 'https://www.bh3.com/index.php/news/_more'; + let type = ctx.params.type; + + const typeMap = { + latest: '', + news: '新闻', + notice: '公告', + activity: '活动', + strategy: '攻略', + }; + + type = typeMap[type] || ''; + + const response = await axios({ + method: 'get', + url: url, + headers: { + 'User-Agent': config.ua, + Referer: url, + 'x-requested-with': 'XMLHttpRequest', + }, + params: { + begin: new Date(), + type: type, + }, + }); + + const data = response.data.data.data; + + const title = `崩坏3-${type ? type : '最新'}`; + + ctx.state.data = { + title: title, + link: `https://www.bh3.com/index.php/news/?type=${type}`, + description: title, + item: data.map((item) => { + const pubDate = new Date(item.create_time); + pubDate.setTime(pubDate.getTime() + 8 * 60 * 60 * 1000); + return { + title: item.title_short ? item.title_short : item.title, + description: item.summary, + pubDate: pubDate.toUTCString(), + link: `https://www.bh3.com/index.php/news/${item.id}`, + }; + }), + }; +}; diff --git a/routes/reimu/category.js b/routes/reimu/category.js new file mode 100644 index 000000000..a49725696 --- /dev/null +++ b/routes/reimu/category.js @@ -0,0 +1,37 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); +const util = require('./util'); + +module.exports = async (ctx) => { + let category = ctx.params.category; + const categoryType = ['3d', 'anime', 'collection', 'picture', 'wallpaper', 'chinese', 'game', 'comic', 'indie', 'recommend', 'music']; + + if (categoryType.indexOf(category) === -1) { + category = categoryType[0]; + } + + const url = `https://blog.reimu.net/archives/category/${category}`; + + const response = await axios({ + method: 'get', + url: url, + headers: { + 'User-Agent': config.ua, + Referer: url, + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + + const articles = $('article'); + const title = $('title').text(); + + ctx.state.data = { + title: title, + link: url, + description: title, + item: util.getArticleData(articles, $), + }; +}; diff --git a/routes/reimu/tag.js b/routes/reimu/tag.js new file mode 100644 index 000000000..2576b0671 --- /dev/null +++ b/routes/reimu/tag.js @@ -0,0 +1,31 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); +const util = require('./util'); + +module.exports = async (ctx) => { + let tag = ctx.params.tag || 'ntr'; + + const url = `https://blog.reimu.net/archives/tag/${tag}`; + + const response = await axios({ + method: 'get', + url: encodeURI(url), // encode中文标签 + headers: { + 'User-Agent': config.ua, + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + + const articles = $('article'); + const title = $('title').text(); + + ctx.state.data = { + title: title, + link: url, + description: title, + item: util.getArticleData(articles, $), + }; +}; diff --git a/routes/reimu/util.js b/routes/reimu/util.js new file mode 100644 index 000000000..eccc86873 --- /dev/null +++ b/routes/reimu/util.js @@ -0,0 +1,24 @@ +const util = { + getArticleData(articles, $) { + if (!articles) return []; + + return articles + .map((index, article) => { + article = $(article); + const title = article.find('h2').text(); + const description = article.find('.entry-content').text(); + const pubDate = new Date(article.find('.entry-date').attr('datetime')).toUTCString(); + const link = article.find('a[rel=bookmark]').attr('href'); + + return { + title, + description, + pubDate, + link, + }; + }) + .get(); + }, +}; + +module.exports = util;