feat: add-playstation-product (#4587)

This commit is contained in:
MisteryMonster
2020-04-28 17:00:07 +08:00
committed by GitHub
parent 4473f2a56e
commit f5c6d6e100
5 changed files with 162 additions and 0 deletions
Regular → Executable
+6
View File
@@ -649,6 +649,12 @@
source: '/zh-hans-hk/grid/:id/:page',
target: '/ps/list/:id',
},
{
title: '折扣|价格',
docs: 'https://docs.rsshub.app/game.html#playstation',
source: ['/:lang/product/:gridName'],
target: '/ps/:lang/product/:gridName',
},
],
www: [
{
Regular → Executable
+10
View File
@@ -80,6 +80,16 @@ Compatible with lists with an URL like <https://store.playstation.com/zh-hans-hk
</RouteEn>
### Game Product Price
<RouteEn author="MisteryMonster" example="/ps/product/UP9000-CUSA00552_00-THELASTOFUS00000" path="/ps/:lang/product/:gridName" :paramsDesc="['region','gridName from the product']" radar="1">
Tested some countries, it should be work for most.
Compatible with Product with an URL like <https://store.playstation.com/en-us/product/HP4497-CUSA16570_00-ASIAFULLGAME0000>. For instance ['Cyberpunk 2077'](https://store.playstation.com/en-us/product/HP4497-CUSA16570_00-ASIAFULLGAME0000) the region is `en-us`, the gridName is `HP4497-CUSA16570_00-ASIAFULLGAME0000`
</RouteEn>
### PlayStation Network user trophy
<RouteEn author="DIYgod" example="/ps/trophy/DIYgod_" path="/ps/trophy/:id" :paramsDesc="['User ID']" radar="1"/>
Regular → Executable
+12
View File
@@ -134,6 +134,18 @@ pageClass: routes
</Route>
### PlayStation Store 游戏折扣|价格
<Route author="MisteryMonster" example="/ps/product/UP9000-CUSA00552_00-THELASTOFUS00000" path="/ps/:lang/product/:gridName" :paramsDesc="['地区语言','游戏的 grid 名']" radar="1">
地区语言如 `zh-hans-hk` 代表香港区简体中文, `zh-hant-tw` 为台湾繁体中文。不同地区游戏 gridName 不同,非中文地区使用英文提示。
适用于 URL 如 <https://store.playstation.com/zh-hans-hk/product/HP4497-CUSA16570_00-ASIAFULLGAME0000> 的游戏。
比如 PlayStation Store 香港简体中文区的 [《赛博朋克 2077》](https://store.playstation.com/zh-hans-hk/product/HP4497-CUSA16570_00-ASIAFULLGAME0000) 的 lang 为 `zh-hans-hk` gridName 为 `HP4497-CUSA16570_00-ASIAFULLGAME0000`
</Route>
### PlayStation Network 用户奖杯
<Route author="DIYgod" example="/ps/trophy/DIYgod_" path="/ps/trophy/:id" :paramsDesc="['用户 ID']" radar="1"/>
+1
View File
@@ -1460,6 +1460,7 @@ router.get('/mlhang', require('./routes/mlhang/latest'));
router.get('/ps/list/:gridName', require('./routes/ps/list'));
router.get('/ps/trophy/:id', require('./routes/ps/trophy'));
router.get('/ps/ps4updates', require('./routes/ps/ps4updates'));
router.get('/ps/:lang?/product/:gridName', require('./routes/ps/product'));
// Quanta Magazine
router.get('/quantamagazine/archive', require('./routes/quantamagazine/archive'));
+133
View File
@@ -0,0 +1,133 @@
const got = require('@/utils/got');
const dayjs = require('dayjs');
module.exports = async (ctx) => {
const { gridName, lang } = ctx.params;
// 默认语言
let langurl = 'zh/HK';
let textshow = {
tprice: `价格`,
tdiscount: `优惠`,
tplusfree: `PLUS 免费`,
tendtime: `此优惠仅限`,
endtimeformat: `YYYY.MM.DD h.mm A`,
treleasedate: `发行日期`,
releasedateformat: `YYYY.MM.DD`,
tsize: `大小`,
tdevice: `设备`,
ttype: `类型`,
trating: `评分`,
tdescribe: `描述`,
tpreview: `预览`,
tnopreview: ``,
};
// 繁体
if (lang === 'zh-hant-hk') {
langurl = `ch/HK`;
}
if (lang === 'zh-hant-tw') {
langurl = `ch/TW`;
}
if (lang.indexOf('hant')) {
textshow = {
tprice: `價格`,
tdiscount: `優惠`,
tplusfree: `PLUS 免費`,
tendtime: `此優惠僅限`,
endtimeformat: `YYYY.MM.DD h.mm A`,
treleasedate: `發售日`,
releasedateformat: `YYYY.MM.DD`,
tsize: `檔案大小`,
tdevice: `播放裝置`,
ttype: `類型`,
trating: `評價`,
tdescribe: `描述`,
tpreview: `預覽`,
tnopreview: ``,
};
}
// English
if (lang.indexOf('-') && lang.indexOf('zh') === -1) {
langurl = ctx.params.lang.replace('-', '/');
textshow = {
tprice: `Price`,
tdiscount: `SAVE`,
tplusfree: `Free For Plus`,
tendtime: `Only in`,
endtimeformat: `MM/DD/YYYY h:mm A`,
treleasedate: `Release Date`,
releasedateformat: `MMMM D, YYYY`,
tsize: `File Size`,
tdevice: `Playable On`,
ttype: `Genre`,
trating: `Rating`,
tdescribe: `Description`,
tpreview: `Preview`,
tnopreview: `None`,
};
}
const response = await got({
method: 'get',
url: `https://store.playstation.com/valkyrie-api/${langurl}/999/resolve/${gridName}?depth=2`,
});
const data = response.data;
const item = data.included && data.included.filter((item) => item.id === `${gridName}`);
ctx.state.data = {
title: `PlayStation Store - ${item[0].attributes.name}`,
link: `https://store.playstation.com/${ctx.params.lang}/product/${gridName}`,
item: item.map((item) => {
let discount = '';
// 折扣,另外这是选择带有特殊字符的JSON数据方法!
let npdiscount = '';
if (item.attributes['badge-info']['non-plus-user']) {
npdiscount = `${textshow.tdiscount} ${item.attributes['badge-info']['non-plus-user']['discount-percentage']}%`;
}
if (
(item.attributes['badge-info']['non-plus-user'] && item.attributes['badge-info']['non-plus-user']['discount-percentage'] === 100) ||
(item.attributes['badge-info']['non-plus-user'] && item.attributes['badge-info']['non-plus-user']['discount-percentage'] === 0)
) {
npdiscount = `${textshow.tprice}:${item.attributes.skus[0].prices['non-plus-user']['actual-price'].display}`;
}
// PLUS折扣
let pdiscount = '';
if (item.attributes['badge-info']['plus-user']) {
pdiscount = `PLUS ${textshow.tdiscount} ${item.attributes['badge-info']['plus-user']['discount-percentage']}%`;
}
if (
(item.attributes['badge-info']['plus-user'] && item.attributes['badge-info']['plus-user']['discount-percentage'] === 100) ||
(item.attributes['badge-info']['plus-user'] && item.attributes['badge-info']['plus-user']['discount-percentage'] === 0)
) {
pdiscount = `${textshow.tplusfree}`;
}
// 优惠时限&判断
let endtime = ``;
if (item.attributes.skus[0].prices['plus-user'].availability['end-date']) {
endtime = `${textshow.tendtime} ${dayjs(item.attributes.skus[0].prices['plus-user'].availability['start-date']).format(textshow.endtimeformat)}--${dayjs(
item.attributes.skus[0].prices['plus-user'].availability['end-date']
).format(textshow.endtimeformat)}。<br><br>`;
}
// 价格,如果有折扣添加折扣信息至标题。
let price = `${textshow.tprice}${item.attributes.skus[0].prices['non-plus-user']['actual-price'].display} | PLUS${textshow.tprice}${item.attributes.skus[0].prices['plus-user']['actual-price'].display}`;
if (item.attributes['badge-info']['non-plus-user']) {
price = `${textshow.tprice}${item.attributes.skus[0].prices['non-plus-user']['actual-price'].display} | PLUS${textshow.tprice}${item.attributes.skus[0].prices['plus-user']['actual-price'].display}<br><br>${endtime}`;
discount = `|${npdiscount} | ${pdiscount}`;
}
return {
title: `${item.attributes.name}${discount}`,
description: `${price}<br>${textshow.treleasedate}${dayjs(item.attributes['release-date']).format(textshow.releasedateformat)}<br><br>
${textshow.tsize}${item.attributes['file-size'].value}${item.attributes['file-size'].unit}<br><br>
${textshow.tdevice}${item.attributes.platforms.join(', ')}<br><br>
${textshow.ttype}${item.attributes.genres.join(', ')}<br><br>
${textshow.trating}${item.attributes['star-rating'].score}<br><br>
${textshow.tdescribe}${item.attributes['long-description']}<br><br>
${textshow.tpreview}${item.attributes['media-list'].preview[0] ? `<video src="${item.attributes['media-list'].preview[0].url}" controls="controls" style="width: 100%"></video>` : textshow.tnopreview}`,
link: `https://store.playstation.com/${ctx.params.lang}/product/${gridName}`,
};
}),
};
};