From 978dc93f0860b246cdb75d740dcd9f375b383191 Mon Sep 17 00:00:00 2001 From: auto-bot-ty <75887908+auto-bot-ty@users.noreply.github.com> Date: Thu, 10 Jun 2021 14:30:49 -0500 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=97=85=E6=B3=95?= =?UTF-8?q?=E5=B8=88=E8=90=A5=E5=9C=B0=E7=94=A8=E6=88=B7=E7=9A=84=E5=B8=96?= =?UTF-8?q?=E5=AD=90=20(#7397)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: auto-bot-ty --- assets/radar-rules.js | 25 ++++++++++++++++++ docs/game.md | 40 ++++++++++++----------------- lib/router.js | 1 + lib/routes/lfsyd/tag.js | 21 ++++++++------- lib/routes/lfsyd/user.js | 48 ++++++++++++++++++++++++++++++++++ lib/routes/lfsyd/utils.js | 54 ++++++++++++++++++++++++++++++--------- 6 files changed, 143 insertions(+), 46 deletions(-) create mode 100644 lib/routes/lfsyd/user.js diff --git a/assets/radar-rules.js b/assets/radar-rules.js index 1238c133e1..43a37b93aa 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -2986,4 +2986,29 @@ }, ], }, + 'iyingdi.com': { + _name: '旅法师营地', + www: [ + { + title: '分区', + docs: 'https://docs.rsshub.app/game.html#lv-fa-shi-ying-di', + source: '/tz/tag/:tag', + target: '/lfsyd/tag/:tag', + }, + { + title: '用户发帖', + docs: 'https://docs.rsshub.app/game.html#lv-fa-shi-ying-di', + source: ['/tz/people/:id', '/tz/people/:id/*'], + target: '/lfsyd/user/:id', + }, + ], + mob: [ + { + title: '分区', + docs: 'https://docs.rsshub.app/game.html#lv-fa-shi-ying-di', + source: '/fine/:tag', + target: '/lfsyd/tag/:tag', + }, + ], + }, }); diff --git a/docs/game.md b/docs/game.md index 57f752ddf8..4a4908b30e 100644 --- a/docs/game.md +++ b/docs/game.md @@ -183,9 +183,9 @@ pageClass: routes 支持的主机平台: -| PS 4 | Xbox One | Switch | PC | Wii U | 3DS | PS Vita | iOS | -| ---- | -------- | ------ | -- | ----- | --- | ------- | --- | -| ps4 | xboxone | switch | pc | wii-u | 3ds | vita | ios | +| PS 4 | Xbox One | Switch | PC | Wii U | 3DS | PS Vita | iOS | +| ---- | -------- | ------ | --- | ----- | --- | ------- | --- | +| ps4 | xboxone | switch | pc | wii-u | 3ds | vita | ios | 发行类型,默认为 `new`: @@ -392,9 +392,9 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 -| 首頁 | PC | TV 掌機 | 手機遊戲 | 動漫畫 | 主題報導 | 活動展覽 | 電競 | -| ---- | -- | ------- | -------- | ------ | -------- | -------- | ---- | -| 缺省 | 1 | 3 | 4 | 5 | 9 | 11 | 13 | +| 首頁 | PC | TV 掌機 | 手機遊戲 | 動漫畫 | 主題報導 | 活動展覽 | 電競 | +| ---- | --- | ------- | -------- | ------ | -------- | -------- | ---- | +| 缺省 | 1 | 3 | 4 | 5 | 9 | 11 | 13 | | Switch | PS5 | PS4 | XboxOne | XboxSX | PC 單機 | PC 線上 | iOS | Android | Web | 漫畫 | 動畫 | | ------ | --- | --- | ------- | ------ | ------- | ------- | --- | ------- | --- | ----- | ----- | @@ -456,34 +456,28 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 ## 旅法师营地 -### 旅法师营地 - - - -| 主页资讯 | 炉石传说 | 万智牌 | 昆特牌 | 游戏王 | 电子游戏 | 手机游戏 | 桌面游戏 | -| -------- | -------- | ------ | ------ | ------ | -------- | -------- | -------- | -| 1 | 2 | 3 | 14 | 16 | 4 | 22 | 9 | - -| 影之诗 | Artifact | 玩家杂谈 | 营地电台 | 2047 | 魂武 | -| ------ | -------- | -------- | -------- | ---- | ---- | -| 17 | 67 | 21 | 5 | 62 | 68 | - - - ### 分区 - + | 炉石传说 | 万智牌 | 游戏王 | 昆特牌 | 影之诗 | 符文之地传奇 | 阴阳师百闻牌 | | :------: | :----: | :----: | :----: | :----: | :----------: | :----------: | -| 17 | 18 | 16 | 19 | 20 | 329 | 221 | +| 17 | 18 | 16 | 19 | 20 | 329 | 221 | | 英雄联盟 | 电子游戏 | 桌面游戏 | 卡牌游戏 | 玩家杂谈 | 二次元 | | :------: | :------: | :------: | :------: | :------: | :----: | -| 112 | 389 | 24 | 102 | 23 | 117 | +| 112 | 389 | 24 | 102 | 23 | 117 | +### 用户的帖子 + + + +可以在用户主页的 URL 中找到 + +Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` + ## 米哈游 ### 崩坏 2 - 游戏公告 diff --git a/lib/router.js b/lib/router.js index f3e96b3ca9..6deaf0e21d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -346,6 +346,7 @@ router.get('/3dm/news', require('./routes/3dm/news_center')); // 旅法师营地 router.get('/lfsyd/:typecode', require('./routes/lfsyd/index')); +router.get('/lfsyd/user/:id', require('./routes/lfsyd/user')); router.get('/lfsyd/tag/:tag', require('./routes/lfsyd/tag')); // 喜马拉雅 diff --git a/lib/routes/lfsyd/tag.js b/lib/routes/lfsyd/tag.js index 784daa72a8..3e1d6ecae1 100644 --- a/lib/routes/lfsyd/tag.js +++ b/lib/routes/lfsyd/tag.js @@ -1,11 +1,10 @@ const got = require('@/utils/got'); const util = require('./utils'); -const timezone = require('@/utils/timezone'); const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const tag_id = ctx.params.tag; - const tag_list = { + const tagId = ctx.params.tag; + const tagList = { 17: '炉石传说', 18: '万智牌', 16: '游戏王', @@ -20,13 +19,13 @@ module.exports = async (ctx) => { 23: '玩家杂谈', 117: '二次元', }; - const tag_name = tag_list[tag_id]; + const tagName = tagList[tagId]; const rootUrl = 'https://www.iyingdi.com'; const tagUrl = 'https://api.iyingdi.com/web/feed/tag-content-list'; const form = { page: 1, size: 30, - tag_id: tag_id, + tag_id: tagId, timestamp: '', version: 0, }; @@ -44,22 +43,22 @@ module.exports = async (ctx) => { form: util.getForm(form), }); const list = response.data.list; - const tag_json = JSON.parse(list[0].feed.tag_json); + const tagJson = JSON.parse(list[0].feed.tag_json); const articleList = list.map((item) => ({ title: item.feed.title, - pubDate: timezone(parseDate(item.feed.show_time * 1000), +8), + pubDate: parseDate(item.feed.show_time * 1000), link: `${rootUrl}/tz/post/${item.feed.source_id}`, guid: item.feed.title, - post_id: item.feed.source_id, + postId: item.feed.source_id, })); const items = await Promise.all(articleList.map(async (item) => await util.ProcessFeed(ctx, item))); ctx.state.data = { - title: `${!tag_name ? tag_json[0].tag : tag_name} - 旅法师营地 `, - link: `${rootUrl}/tz/tag/${tag_id}`, - description: `${!tag_name ? tag_json[0].tag : tag_name} - 旅法师营地 `, + title: `${!tagName ? tagJson[0].tag : tagName} - 旅法师营地 `, + link: `${rootUrl}/tz/tag/${tagId}`, + description: `${!tagName ? tagJson[0].tag : tagName} - 旅法师营地 `, item: items, }; }; diff --git a/lib/routes/lfsyd/user.js b/lib/routes/lfsyd/user.js new file mode 100644 index 0000000000..e4db860cab --- /dev/null +++ b/lib/routes/lfsyd/user.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); +const util = require('./utils'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const rootUrl = 'https://www.iyingdi.com'; + const listUrl = 'https://api.iyingdi.com/web/user/event-list'; + const form = { + event_types: 'content', + page: 1, + size: 15, + timestamp: '', + user_id: id, + }; + + const response = await got({ + method: 'post', + url: listUrl, + headers: { + Host: 'api.iyingdi.com', + 'Login-Token': 'nologin', + Origin: rootUrl, + Platform: 'pc', + Referer: `${rootUrl}/tz/people/${id}/postList`, + }, + form: util.getForm(form), + }); + const list = response.data.data; + const nickname = list[0].author.nickname; + + const articleList = list.map((item) => ({ + title: item.event_data.title, + pubDate: parseDate(item.event_data.show_time * 1000), + link: `${rootUrl}/tz/post/${item.event_data.post_id}`, + guid: item.event_data.title, + postId: item.event_data.post_id, + })); + + const items = await Promise.all(articleList.map(async (item) => await util.ProcessFeed(ctx, item))); + + ctx.state.data = { + title: `${nickname} - 旅法师营地 `, + link: `${rootUrl}/tz/people/${id}`, + description: `${nickname} - 旅法师营地`, + item: items, + }; +}; diff --git a/lib/routes/lfsyd/utils.js b/lib/routes/lfsyd/utils.js index c8542923b3..e16a010845 100644 --- a/lib/routes/lfsyd/utils.js +++ b/lib/routes/lfsyd/utils.js @@ -1,14 +1,14 @@ +const cheerio = require('cheerio'); const got = require('@/utils/got'); const md5 = require('@/utils/md5'); +const rootUrl = 'https://www.iyingdi.com'; const ProcessFeed = async (ctx, item) => { const infoUrL = 'https://api.iyingdi.com/web/post/info'; - const rootUrl = 'https://www.iyingdi.com'; - const info_form = { - post_id: item.post_id, + const infoForm = { + post_id: item.postId, timestamp: '', }; - const description = await ctx.cache.tryGet(item.link, async () => { const response = await got({ method: 'post', @@ -20,25 +20,55 @@ const ProcessFeed = async (ctx, item) => { Platform: 'pc', Referer: `${rootUrl}/`, }, - form: getForm(info_form), + form: getForm(infoForm), }); - const content_body = JSON.parse(response.body); - return content_body.post.content; + return cleanHtml(JSON.parse(response.body).post.content); }); - item.description = description; - delete item.post_id; + delete item.postId; return item; }; - -const getForm = function (form) { - const key = 'b8d5b38577b8bb382b0c783b474b95f9'; +const getForm = function (form, type) { + const key = type ? '8a11ed3712b699e749185674f1dc20b4' : 'b8d5b38577b8bb382b0c783b474b95f9'; form.key = key; form.timestamp = Math.floor(new Date().getTime() / 1000); form.sign = md5(new URLSearchParams(form).toString()); delete form.key; return form; }; + +const cleanHtml = function (htmlString) { + const regex = new RegExp('(

|

)(.*?)?(标准|狂野)日报投稿.*?(.*?)?(

|
)(.|\n)*$'); + const $ = cheerio.load(htmlString.replace(regex, '')); + $('.yingdi-car,.bbspost,.deck-set').each(function (i, e) { + const className = $(e).attr('class'); + const dataId = $(e).attr('data-id'); + const decksUrl = `${rootUrl}/web/tools/hearthstone/decks/setdetail?setid=${dataId}`; + const url = className === 'yingdi-card bbspost' ? `${rootUrl}/tz/post/${dataId}` : decksUrl; + $(e).find('.card-status').remove(); + $(e).find('.card-info').wrap(``); + }); + + $('.yingdi-image.gif').each(function (i, e) { + const imgsrc = $(e).attr('data-original'); + $(e).attr('src', imgsrc); + }); + + $('.yingdi-audio').each(function (i, e) { + $(e).find('.audio-cover').remove(); + $(e).find('.audio-area.hidden').attr('class', 'audio-area'); + }); + + // 用户头像 + $('.yingdi-card.user').remove(); + // 套牌代码复制 + $('.action-button').remove(); + // 投票 + $('.yingdi-ballot').remove(); + $('hr').remove(); + return $.html(); +}; + module.exports = { getForm, ProcessFeed,