feat: add Metacritic game releases (#2366)

This commit is contained in:
Henry Wang
2019-06-11 11:28:17 +08:00
committed by DIYgod
parent d787da7d6a
commit d9e2bcd4d9
6 changed files with 116 additions and 8 deletions
+26
View File
@@ -343,6 +343,32 @@ Compatible with lists with an URL like <https://store.playstation.com/zh-hans-hk
</RouteEn>
## Metacritic
### Game Releases
<RouteEn author="HenryQW" example="/metacritic/release/switch/coming" path="/metacritic/release/:platform/:type?/:sort?" :paramsDesc="['console platform', 'release type, default to `new`', 'sorting type, default to `date`']">
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 |
</RouteEn>
## ACG
### Vol.moe
+26
View File
@@ -44,6 +44,32 @@ pageClass: routes
<Route author="dearrrfish" example="/maxnews/dota2" path="maxnews/dota2" />
## Metacritic
### 新游发行
<Route author="HenryQW" example="/metacritic/release/switch/coming" path="/metacritic/release/:platform/:type?/:sort?" :paramsDesc="['主机平台', '发行类型,默认为 `new`', '排序类型,默认为`date`']">
支持的主机平台:
| 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 |
</Route>
## Nintendo
### eShop 新发售游戏
+10 -8
View File
@@ -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;
+54
View File
@@ -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} <br> Metacritic Score: ${item.metascore} <br> User Score: ${item.userscore} <br>`,
link: item.url,
})),
};
};