feat: psn trophy

This commit is contained in:
DIYgod 2019-08-30 00:07:54 +08:00
parent a4f8693d88
commit a73d0418bf
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
3 changed files with 100 additions and 2 deletions

View File

@ -90,9 +90,9 @@ pageClass: routes
<Route author="HFO4" example="/nintendo/direct" path="/nintendo/direct"/>
## PlayStation Store
## PlayStation
### 游戏列表
### PlayStation Store 游戏列表
<Route author="DIYgod" example="/ps/list/STORE-MSF86012-PLUS_FTT_CONTENT" path="/ps/list/:gridName" :paramsDesc="['列表的 grid 名']">
@ -100,6 +100,10 @@ pageClass: routes
</Route>
### PlayStation Network 用户奖杯
<Route author="DIYgod" example="/ps/trophy/DIYgod_" path="/ps/trophy/:id" :paramsDesc="['用户 ID']"/>
## psnine
### 首页-白金攻略/游戏开箱

View File

@ -1268,6 +1268,7 @@ router.get('/mlhang', require('./routes/mlhang/latest'));
// PlayStation Store
router.get('/ps/list/:gridName', require('./routes/ps/list'));
router.get('/ps/trophy/:id', require('./routes/ps/trophy'));
// Nintendo
router.get('/nintendo/eshop/jp', require('./routes/nintendo/eshop_jp'));

93
lib/routes/ps/trophy.js Normal file
View File

@ -0,0 +1,93 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const response = await got({
method: 'get',
url: `https://psnprofiles.com/${id}?order=last-trophy`,
});
const $ = cheerio.load(response.data);
const list = $('.zebra tr')
.filter(function() {
return (
$(this)
.find('.progress-bar span')
.text() !== '0%'
);
})
.map((i, e) =>
$(e)
.find('.title')
.attr('href')
)
.get()
.slice(0, 3);
const items = await Promise.all(
list.map(async (item) => {
const link = 'https://psnprofiles.com' + item + '?order=date&trophies=earned&lang=zh-cn';
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
const list = $('.zebra tr.completed');
const items = list
.map((i, item) => {
item = $(item);
return {
title:
item.find('.title').text() +
' - ' +
$('.page h3')
.eq(0)
.text()
.trim(),
description: `<img src="${item.find('.trophy img').attr('src')}"><br>${item
.find('.title')
.parent()
.contents()
.filter(function() {
return this.nodeType === 3;
})
.text()
.trim()}<br>珍贵度${item.find('.hover-show .typo-top').text()}`,
link: 'https://psnprofiles.com' + item.find('.title').attr('href'),
pubDate: new Date(
+new Date(
item
.find('.typo-top-date nobr')
.contents()
.filter(function() {
return this.nodeType === 3;
})
.text() +
' ' +
item.find('.typo-bottom-date').text()
) +
8 * 60 * 60 * 1000
).toUTCString(),
};
})
.get();
return Promise.resolve(items);
})
);
let result = [];
items.forEach((item) => {
result = result.concat(item);
});
ctx.state.data = {
title: `${id} 的 PSN 奖杯`,
link: `https://psnprofiles.com/${id}/log`,
item: result,
};
};