diff --git a/docs/en/README.md b/docs/en/README.md index 1e3615f08..2b5475916 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -343,6 +343,32 @@ Compatible with lists with an URL like +## Metacritic + +### Game Releases + + + +Platforms supported: + +| PS 4 | Xbox One | Switch | PC | Wii U | 3DS | PS Vita | iOS | +| ---- | -------- | ------ | --- | ----- | --- | ------- | --- | +| ps4 | xboxone | switch | pc | wii-u | 3ds | vita | ios | + +Release types, default to `new`: + +| New | Coming Soon | All | +| --- | ----------- | --- | +| new | coming | all | + +Sorting types, default to `date`: + +| Date | Metacritic Score | User Score | +| ---- | ---------------- | ---------- | +| date | metascore | userscore | + + + ## ACG ### Vol.moe diff --git a/docs/game.md b/docs/game.md index e7b5e4f35..8f01cb01a 100644 --- a/docs/game.md +++ b/docs/game.md @@ -44,6 +44,32 @@ pageClass: routes +## Metacritic + +### 新游发行 + + + +支持的主机平台: + +| PS 4 | Xbox One | Switch | PC | Wii U | 3DS | PS Vita | iOS | +| ---- | -------- | ------ | --- | ----- | --- | ------- | --- | +| ps4 | xboxone | switch | pc | wii-u | 3ds | vita | ios | + +发行类型,默认为 `new`: + +| 新游发行 | 即将发行 | 全部 | +| -------- | -------- | ---- | +| new | coming | all | + +排序类型,默认为`date`: + +| 日期 | Metacritic 评分 | 用户评分 | +| ---- | --------------- | --------- | +| date | metascore | userscore | + + + ## Nintendo ### eShop 新发售游戏 diff --git a/lib/router.js b/lib/router.js index e86b19739..46055a167 100644 --- a/lib/router.js +++ b/lib/router.js @@ -319,9 +319,6 @@ router.get('/tingshuitz/xian', require('./routes/tingshuitz/xian')); router.get('/tingshuitz/yangjiang', require('./routes/tingshuitz/yangjiang')); router.get('/tingshuitz/nanjing', require('./routes/tingshuitz/nanjing')); -// MIUI 更新 -router.get('/miui/:device/:type?/:region?', require('./routes/miui/index')); - // 米哈游 router.get('/mihoyo/bh3/:type', require('./routes/mihoyo/bh3')); router.get('/mihoyo/bh2/:type', require('./routes/mihoyo/bh2')); @@ -368,6 +365,8 @@ router.get('/hexo/yilia/:url', require('./routes/hexo/yilia')); router.get('/mi/crowdfunding', require('./routes/mi/crowdfunding')); router.get('/mi/youpin/crowdfunding', require('./routes/mi/youpin/crowdfunding')); router.get('/mi/youpin/new', require('./routes/mi/youpin/new')); +// MIUI 更新 +router.get('/miui/:device/:type?/:region?', require('./routes/mi/miui/index')); // Keep router.get('/keep/user/:id', require('./routes/keep/user')); @@ -953,6 +952,9 @@ router.get('/huxiu/author/:id', require('./routes/huxiu/author')); router.get('/steam/search/:params', require('./routes/steam/search')); router.get('/steam/news/:appids', require('./routes/steam/news')); +// Steamgifts +router.get('/steamgifts/discussions/:category?', require('./routes/steam/steamgifts/discussions')); + // 扇贝 router.get('/shanbay/checkin/:id', require('./routes/shanbay/checkin')); @@ -1351,16 +1353,13 @@ router.get('/digitaling/projects/:category', require('./routes/digitaling/projec // Bing壁纸 router.get('/bing', require('./routes/bing/index')); -// MaxNews - DotA 2 +// Maxjia News - DotA 2 router.get('/maxnews/dota2', require('./routes/maxnews/dota2')); // 柠檬 - 私房歌 router.get('/ningmeng/song', require('./routes/ningmeng/song')); -// Steamgifts -router.get('/steamgifts/discussions/:category?', require('./routes/steamgifts/discussions')); - -// Steamgifts +// 紫竹张 router.get('/zzz', require('./routes/zzz/index')); // AlgoCasts @@ -1398,4 +1397,7 @@ router.get('/polimi/news/:language?', require('./routes/polimi/news')); // 东方网-上海 router.get('/eastday/sh', require('./routes/eastday/sh')); +// Metacritic +router.get('/metacritic/release/:platform/:type/:sort?', require('./routes/metacritic/release')); + module.exports = router; diff --git a/lib/routes/metacritic/release.js b/lib/routes/metacritic/release.js new file mode 100644 index 000000000..f9aeba866 --- /dev/null +++ b/lib/routes/metacritic/release.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + let type = 'new-releases'; + let title = 'New Releases'; + + const sort = ctx.params.sort || 'date'; + + switch (ctx.params.type) { + case 'coming': + type = 'coming-soon'; + title = 'Coming Soon'; + break; + case 'all': + type = 'available'; + title = 'All Releases'; + break; + } + + const url = `https://www.metacritic.com/browse/games/release-date/${type}/${ctx.params.platform}/${sort}`; + + const response = await got({ + method: 'get', + url, + }); + const data = response.body; + + const $ = cheerio.load(data); + const list = $('.list_products > li') + .get() + .slice(0, 10); + + const result = list.map((item) => { + const $ = cheerio.load(item); + return { + title: $('.product_title').text(), + url: 'https://www.metacritic.com' + $('.product_title > a').attr('href'), + metascore: $('.brief_metascore').text(), + userscore: $('.textscore').text(), + date: $('.release_date > .data').text(), + }; + }); + + ctx.state.data = { + title: `Metacritic ${ctx.params.platform} ${title}`, + link: url, + item: result.map((item) => ({ + title: `${item.metascore === 'tbd' ? '' : [item.metascore]} ${item.title}`, + description: `Release Date: ${item.date}
Metacritic Score: ${item.metascore}
User Score: ${item.userscore}
`, + link: item.url, + })), + }; +}; diff --git a/lib/routes/miui/index.js b/lib/routes/mi/miui/index.js similarity index 100% rename from lib/routes/miui/index.js rename to lib/routes/mi/miui/index.js diff --git a/lib/routes/steamgifts/discussions.js b/lib/routes/steam/steamgifts/discussions.js similarity index 100% rename from lib/routes/steamgifts/discussions.js rename to lib/routes/steam/steamgifts/discussions.js