diff --git a/assets/radar-rules.js b/assets/radar-rules.js old mode 100644 new mode 100755 index 2e6057168f..29bed7cfc3 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -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: [ { diff --git a/docs/en/game.md b/docs/en/game.md old mode 100644 new mode 100755 index 14f2ed51d8..76b0acf241 --- a/docs/en/game.md +++ b/docs/en/game.md @@ -80,6 +80,16 @@ Compatible with lists with an URL like +### Game Product Price + + + +Tested some countries, it should be work for most. + +Compatible with Product with an URL like . 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` + + + ### PlayStation Network user trophy diff --git a/docs/game.md b/docs/game.md old mode 100644 new mode 100755 index 3fe1f47ef9..7d2011360e --- a/docs/game.md +++ b/docs/game.md @@ -134,6 +134,18 @@ pageClass: routes +### PlayStation Store 游戏折扣|价格 + + + +地区语言如 `zh-hans-hk` 代表香港区简体中文, `zh-hant-tw` 为台湾繁体中文。不同地区游戏 gridName 不同,非中文地区使用英文提示。 + +适用于 URL 如 的游戏。 + +比如 PlayStation Store 香港简体中文区的 [《赛博朋克 2077》](https://store.playstation.com/zh-hans-hk/product/HP4497-CUSA16570_00-ASIAFULLGAME0000) 的 lang 为 `zh-hans-hk`, gridName 为 `HP4497-CUSA16570_00-ASIAFULLGAME0000` + + + ### PlayStation Network 用户奖杯 diff --git a/lib/router.js b/lib/router.js index 6d22b1e2c6..c7094a43c6 100755 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/ps/product.js b/lib/routes/ps/product.js new file mode 100755 index 0000000000..08bbbbcb5d --- /dev/null +++ b/lib/routes/ps/product.js @@ -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)}。

`; + } + // 价格,如果有折扣添加折扣信息至标题。 + 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}

${endtime}`; + discount = `|${npdiscount} | ${pdiscount}`; + } + + return { + title: `${item.attributes.name}${discount}`, + description: `${price}
${textshow.treleasedate}:${dayjs(item.attributes['release-date']).format(textshow.releasedateformat)}

+ ${textshow.tsize}:${item.attributes['file-size'].value}${item.attributes['file-size'].unit}

+ ${textshow.tdevice}:${item.attributes.platforms.join(', ')}

+ ${textshow.ttype}:${item.attributes.genres.join(', ')}

+ ${textshow.trating}:${item.attributes['star-rating'].score}

+ ${textshow.tdescribe}:${item.attributes['long-description']}

+ ${textshow.tpreview}:${item.attributes['media-list'].preview[0] ? `` : textshow.tnopreview}`, + link: `https://store.playstation.com/${ctx.params.lang}/product/${gridName}`, + }; + }), + }; +};