From 76fcc69c4317e7bb67b5d88c6df0f88924a25fc0 Mon Sep 17 00:00:00 2001 From: CC Date: Wed, 27 Dec 2023 15:14:05 +0800 Subject: [PATCH] PlayStation Monthly Games --- assets/radar-rules.js | 11 --- lib/radar-rules.js | 27 ------- lib/router.js | 6 -- lib/routes/ps/list.js | 34 -------- lib/routes/ps/product.js | 133 -------------------------------- lib/routes/ps/ps4updates.js | 60 -------------- lib/v2/ps/maintainer.js | 4 + lib/v2/ps/monthly-games.js | 26 +++++++ lib/v2/ps/radar.js | 17 ++++ lib/v2/ps/router.js | 4 + lib/{routes => v2}/ps/trophy.js | 0 website/docs/routes/game.mdx | 18 +---- 12 files changed, 53 insertions(+), 287 deletions(-) delete mode 100644 lib/routes/ps/list.js delete mode 100755 lib/routes/ps/product.js delete mode 100644 lib/routes/ps/ps4updates.js create mode 100644 lib/v2/ps/maintainer.js create mode 100644 lib/v2/ps/monthly-games.js create mode 100644 lib/v2/ps/radar.js create mode 100644 lib/v2/ps/router.js rename lib/{routes => v2}/ps/trophy.js (100%) diff --git a/assets/radar-rules.js b/assets/radar-rules.js index 07dee835d..43bcbba21 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -52,17 +52,6 @@ ], }, 'www.chicagotribune.com': { _name: 'Chicago Tribune', www: [{ title: 'Chicago Tribune', docs: 'https://docs.rsshub.app/routes/traditional_media#chicago-tribune', source: '/' }] }, - 'playstation.com': { - _name: 'PlayStation', - store: [ - { title: '游戏列表', docs: 'https://docs.rsshub.app/routes/game#playstation', source: '/zh-hans-hk/grid/:id/:page', target: '/ps/list/:id' }, - { title: '折扣|价格', docs: 'https://docs.rsshub.app/routes/game#playstation', source: ['/:lang/product/:gridName'], target: '/ps/:lang/product/:gridName' }, - ], - www: [ - { title: '用户奖杯', docs: 'https://docs.rsshub.app/routes/game#playstation' }, - { title: '系统更新纪录', docs: 'https://docs.rsshub.app/routes/game#playstation' }, - ], - }, 'monsterhunter.com': { _name: '怪物猎人世界', www: [ diff --git a/lib/radar-rules.js b/lib/radar-rules.js index 24304fe17..1040ea02e 100644 --- a/lib/radar-rules.js +++ b/lib/radar-rules.js @@ -66,33 +66,6 @@ module.exports = { }, ], }, - 'playstation.com': { - _name: 'PlayStation', - store: [ - { - title: '游戏列表', - docs: 'https://docs.rsshub.app/routes/game#playstation', - source: '/zh-hans-hk/grid/:id/:page', - target: '/ps/list/:id', - }, - { - title: '折扣|价格', - docs: 'https://docs.rsshub.app/routes/game#playstation', - source: ['/:lang/product/:gridName'], - target: '/ps/:lang/product/:gridName', - }, - ], - www: [ - { - title: '用户奖杯', - docs: 'https://docs.rsshub.app/routes/game#playstation', - }, - { - title: '系统更新纪录', - docs: 'https://docs.rsshub.app/routes/game#playstation', - }, - ], - }, 'monsterhunter.com': { _name: '怪物猎人世界', www: [ diff --git a/lib/router.js b/lib/router.js index 5958b06b0..5d08b2a95 100644 --- a/lib/router.js +++ b/lib/router.js @@ -638,12 +638,6 @@ router.get('/bupt/funbox', lazyloadRouteHandler('./routes/universities/bupt/funb // 广东海洋大学 router.get('/gdoujwc', lazyloadRouteHandler('./routes/universities/gdou/jwc/jwtz')); -// PlayStation Store -router.get('/ps/list/:gridName', lazyloadRouteHandler('./routes/ps/list')); -router.get('/ps/trophy/:id', lazyloadRouteHandler('./routes/ps/trophy')); -router.get('/ps/ps4updates', lazyloadRouteHandler('./routes/ps/ps4updates')); -router.get('/ps/:lang?/product/:gridName', lazyloadRouteHandler('./routes/ps/product')); - // Quanta Magazine router.get('/quantamagazine/archive', lazyloadRouteHandler('./routes/quantamagazine/archive')); diff --git a/lib/routes/ps/list.js b/lib/routes/ps/list.js deleted file mode 100644 index b24ef6f0e..000000000 --- a/lib/routes/ps/list.js +++ /dev/null @@ -1,34 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const gridName = ctx.params.gridName; - - const response = await got({ - method: 'get', - url: `https://store.playstation.com/valkyrie-api/zh/HK/19/container/${gridName}?size=30&bucket=games&start=0`, - headers: { - Referer: `https://store.playstation.com/zh-hans-hk/grid/${gridName}/1`, - }, - }); - const data = response.data; - const items = data.included && data.included.filter((item, index) => index % 2); - const sub = data.included && data.included.filter((item, index) => !(index % 2)); - - ctx.state.data = { - title: `PlayStation Store - ${data.data.attributes.name}`, - link: `https://store.playstation.com/zh-hans-hk/grid/${gridName}/1`, - item: - items && - items.map((item, index) => ({ - title: `${item.attributes.name} (${sub[index].attributes.name})`, - description: `大小:${item.attributes['file-size'].value}${item.attributes['file-size'].unit}

设备:${item.attributes.platforms.join(', ')}

类型:${item.attributes.genres.join(', ')}

评分:${ - item.attributes['star-rating'].score - }

描述:${item.attributes['long-description']}

预览:${ - item.attributes['media-list'] && item.attributes['media-list'].preview && item.attributes['media-list'].preview[0] && item.attributes['media-list'].preview[0].url - ? `` - : '无' - }`, - link: `https://store.playstation.com/zh-hans-hk/product/${item.id}`, - })), - }; -}; diff --git a/lib/routes/ps/product.js b/lib/routes/ps/product.js deleted file mode 100755 index 8ac01b01a..000000000 --- a/lib/routes/ps/product.js +++ /dev/null @@ -1,133 +0,0 @@ -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?.filter((item) => item.id === gridName) ?? []; - ctx.state.data = { - title: `PlayStation Store - ${item[0].attributes?.name ?? 'Unknown 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}`, - }; - }), - }; -}; diff --git a/lib/routes/ps/ps4updates.js b/lib/routes/ps/ps4updates.js deleted file mode 100644 index 910a5f4ce..000000000 --- a/lib/routes/ps/ps4updates.js +++ /dev/null @@ -1,60 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const url = require('url'); -const host = 'https://asia.playstation.com/'; -module.exports = async (ctx) => { - const link = `https://asia.playstation.com/chs-hk/ps4/system-update/ps4-system-update-change-log/`; - const response = await got.get(link, { - responseType: 'buffer', - }); - const $ = cheerio.load(response.data); - // let title = $('.psc-main-format-style').first().text(); - function sortDate(e) { - // console.log(e); - const pubday = e.substr(8, 2); - const pubmonth = e.substr(5, 2); - const pubyear = e.substr(0, 4); - const pubdateString = pubmonth + `-` + pubday + `-` + pubyear; - // console.log(pubdateString); - return pubdateString; - } - const list = $('.layoutRowParsys ul li') - .map(function () { - const info = { - title: $(this).find('span.psc-d-block').text(), - link: $(this).find('a').attr('href'), - date: sortDate($(this).find('span.psc-info-date').text()), - }; - return info; - }) - .get(); - const out = await Promise.all( - list.map(async (info) => { - const title = info.title; - const date = info.date; - const itemUrl = url.resolve(host, info.link); - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - const response = await got.get(itemUrl, { - responseType: 'buffer', - }); - const $ = cheerio.load(response.data); - const description = $('.layoutRowParsys').html(); - const single = { - title, - link: itemUrl, - description, - pubDate: new Date(date).toDateString(), - }; - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - ctx.state.data = { - title: $('.psc-main-format-style').first().text(), - link, - item: out, - }; -}; diff --git a/lib/v2/ps/maintainer.js b/lib/v2/ps/maintainer.js new file mode 100644 index 000000000..c706bf74d --- /dev/null +++ b/lib/v2/ps/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/monthly-games': ['justjustCC'], + '/trophy/:id': ['DIYgod'], +}; diff --git a/lib/v2/ps/monthly-games.js b/lib/v2/ps/monthly-games.js new file mode 100644 index 000000000..b28553c43 --- /dev/null +++ b/lib/v2/ps/monthly-games.js @@ -0,0 +1,26 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const baseUrl = 'https://www.playstation.com/en-sg/ps-plus/whats-new/'; + + const { data: response } = await got(baseUrl); + const $ = cheerio.load(response); + + const list = $('.cmp-experiencefragment--your-latest-monthly-games .box') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('h3').text(), + description: `${item.find('h3 + p').text()}`, + link: item.find('.button a').attr('href'), + }; + }); + + ctx.state.data = { + title: 'PlayStation Plus Latest Monthly Games', + link: baseUrl, + item: list, + }; +}; diff --git a/lib/v2/ps/radar.js b/lib/v2/ps/radar.js new file mode 100644 index 000000000..98427a5fb --- /dev/null +++ b/lib/v2/ps/radar.js @@ -0,0 +1,17 @@ +module.exports = { + 'playstation.com': { + _name: 'PlayStation Store', + www: [ + { + title: 'PlayStation Monthly Games', + docs: 'https://docs.rsshub.app/routes/game#playstation-store', + source: ['/en-sg/ps-plus/whats-new'], + target: '/ps/monthly-games', + }, + { + title: 'PlayStation Network user trophy', + docs: 'https://docs.rsshub.app/routes/game#playstation-store', + }, + ], + }, +}; diff --git a/lib/v2/ps/router.js b/lib/v2/ps/router.js new file mode 100644 index 000000000..3dbdf3d4d --- /dev/null +++ b/lib/v2/ps/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/monthly-games', require('./monthly-games')); + router.get('/trophy/:id', require('./trophy')); +}; diff --git a/lib/routes/ps/trophy.js b/lib/v2/ps/trophy.js similarity index 100% rename from lib/routes/ps/trophy.js rename to lib/v2/ps/trophy.js diff --git a/website/docs/routes/game.mdx b/website/docs/routes/game.mdx index 80f3f2ee5..a96442a79 100644 --- a/website/docs/routes/game.mdx +++ b/website/docs/routes/game.mdx @@ -336,27 +336,13 @@ ## PlayStation Store {#playstation-store} -### Game List(Hong Kong) {#playstation-store-game-list-hong-kong} - - - Compatible with lists with an URL like `https://store.playstation.com/zh-hans-hk/grid/STORE-MSF86012-PLUS_FTT_CONTENT`. For instance [PSN Free to Play](https://store.playstation.com/zh-hans-hk/grid/STORE-MSF86012-PLUS_FTT_CONTENT), the gridName is `STORE-MSF86012-PLUS_FTT_CONTENT` - - -### Game Product Price {#playstation-store-game-product-price} - - - 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` - - ### PlayStation Network user trophy {#playstation-store-playstation-network-user-trophy} -### PlayStation 4 System Update {#playstation-store-playstation-4-system-update} +### PlayStation Monthly Games {#playstation-store-playstation-monthly-games} - + ## psnine {#psnine}