From 4747d935ccfa805f172fb52ddf808873c7c6a98d Mon Sep 17 00:00:00 2001
From: cssxsh <32539286+cssxsh@users.noreply.github.com>
Date: Fri, 18 Oct 2019 11:53:27 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20add=20Dengekionline(=E9=9B=BB=E6=92=83?=
=?UTF-8?q?=E3=82=AA=E3=83=B3=E3=83=A9=E3=82=A4=E3=83=B3)=20(#3269)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/anime.md | 12 +++
lib/router.js | 3 +
lib/routes/dengekionline/new.js | 130 ++++++++++++++++++++++++++++++++
3 files changed, 145 insertions(+)
create mode 100644 lib/routes/dengekionline/new.js
diff --git a/docs/anime.md b/docs/anime.md
index 38db46aa6e..b87291ff2c 100644
--- a/docs/anime.md
+++ b/docs/anime.md
@@ -210,3 +210,15 @@ pageClass: routes
### 最新汉化
+
+## 電撃オンライン
+
+### 最新記事
+
+
+
+| All | PlayStation | Nintendo | Xbox | PC | Girl’sStyle | Arcade Web | App | Anime | Review | Rank |
+| --- | ----------- | -------- | --------- | --- | ----------- | ---------- | --- | ----- | ------ | ---- |
+| | dps | nintendo | microsoft | dpc | gstyle | arcade | app | anime | review | rank |
+
+
diff --git a/lib/router.js b/lib/router.js
index 665f61c458..d32c396ff6 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1833,6 +1833,9 @@ router.get('/kzfeed/topic/:id', require('./routes/kzfeed/topic'));
// 腾讯新闻较真查证平台
router.get('/factcheck', require('./routes/tencent/factcheck'));
+// 電撃Online
+router.get('/dengekionline/:type?', require('./routes/dengekionline/new'));
+
// 4Gamers
router.get('/4gamers/category/:category', require('./routes/4gamers/category'));
router.get('/4gamers/tag/:tag', require('./routes/4gamers/tag'));
diff --git a/lib/routes/dengekionline/new.js b/lib/routes/dengekionline/new.js
new file mode 100644
index 0000000000..06abf3c2fb
--- /dev/null
+++ b/lib/routes/dengekionline/new.js
@@ -0,0 +1,130 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+const host = 'https://dengekionline.com';
+const infos = {
+ '': {
+ category: '電撃総合',
+ patch: '/',
+ },
+ dps: {
+ category: '電撃PlayStation',
+ patch: '/dps/',
+ },
+ nintendo: {
+ category: '電撃Nintendo',
+ patch: '/nintendo/',
+ },
+ microsoft: {
+ category: '電撃Xbox',
+ patch: '/microsoft/',
+ },
+ dpc: {
+ category: '電撃PC',
+ patch: '/dpc/',
+ },
+ gstyle: {
+ category: '電撃Girl’sStyle',
+ patch: '/g-style/',
+ },
+ arcade: {
+ category: '電撃アーケードWeb',
+ patch: '/arcade/',
+ },
+ app: {
+ category: 'アプリまとめ',
+ patch: '/app/',
+ },
+ anime: {
+ category: 'アニメ',
+ patch: '/tags/%E3%82%A2%E3%83%8B%E3%83%A1/',
+ },
+ review: {
+ category: 'レビューまとめ',
+ patch: '/tags/%E3%83%AC%E3%83%93%E3%83%A5%E3%83%BC/',
+ },
+ rank: {
+ category: '販売ランキング',
+ patch: '/tags/%E3%82%BD%E3%83%95%E3%83%88%E8%B2%A9%E5%A3%B2%E3%83%A9%E3%83%B3%E3%82%AD%E3%83%B3%E3%82%B0/',
+ },
+};
+
+module.exports = async (ctx) => {
+ // 设置参数
+ const info = infos[ctx.params.type || ''];
+ if (info === undefined) {
+ throw Error('不存在的类型');
+ }
+ const patch = info.patch;
+ const category = info.category;
+ const title = `電撃オンライン - ${category}`;
+ // 网页请求获取新闻列表
+ const response = await got(patch, {
+ method: 'get',
+ baseUrl: host,
+ });
+ const data = response.data;
+ const link = response.link;
+ // 过滤处理新闻列表数据
+ const $ = cheerio.load(data);
+ const list = $('ul.gNews_list').find('a');
+ const description = $('meta[name="description"]').attr('content');
+ // 整理信息
+ const item = await Promise.all(
+ list
+ .map(async (index, element) => {
+ const liArr = $(element).find('li');
+ const date = $(element)
+ .find('time')
+ .attr('datetime');
+
+ const newLink = $(element).attr('href');
+ const category = liArr.map((index, li) => $(li).text()).get();
+ // 日本时区为东9区
+ const pubDate = new Date(`${date} GMT+0900`).toUTCString();
+ // 获取作者等
+ const newInfo = await ctx.cache.tryGet(newLink, async () => {
+ // console.log(newLink);
+ const result = await got(newLink, {
+ method: 'get',
+ baseUrl: host,
+ });
+ const $ = cheerio.load(result.data);
+ const title = $('.gEntry_title').text();
+ const description = $('.gEntry_body')
+ .find('p')
+ .html();
+ const author = $('.gEntry_athorList')
+ .find('dd')
+ .text();
+ const info = {
+ title: title,
+ description: description,
+ author: author,
+ url: result.url,
+ };
+ return info;
+ });
+
+ const single = {
+ title: newInfo.title,
+ link: newInfo.url,
+ category: category,
+ description: newInfo.description,
+ author: newInfo.author,
+ guid: newInfo.url,
+ pubDate: pubDate,
+ };
+ return Promise.resolve(single);
+ })
+ .get()
+ );
+ // 设置rss
+ ctx.state.data = {
+ title: title,
+ description: description,
+ link: link,
+ language: 'ja-jp',
+ item: item,
+ };
+};