mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 06:30:40 +08:00
feat: added steamdb free games (#4372)
This commit is contained in:
10
docs/game.md
10
docs/game.md
@@ -190,6 +190,16 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
|
||||
|
||||
<Route author="maple3142" example="/steam/news/282800" path="/steam/news/:appids" :paramsDesc="['游戏 id']" radar="1"/>
|
||||
|
||||
## SteamDB
|
||||
|
||||
### 免费游戏
|
||||
|
||||
<Route author="dearrrfish" example="/steamdb/free" path="/steamdb/free/:type?" :paramsDesc="['免费类型,留空为不过滤']"/>
|
||||
|
||||
| 全部 | 周末 | 永久 |
|
||||
| ------ | ------- | ---- |
|
||||
| <留空> | weekend | keep |
|
||||
|
||||
## SteamGifts
|
||||
|
||||
### Discussions
|
||||
|
||||
@@ -1069,6 +1069,9 @@ router.get('/steam/news/:appids', require('./routes/steam/news'));
|
||||
// Steamgifts
|
||||
router.get('/steamgifts/discussions/:category?', require('./routes/steam/steamgifts/discussions'));
|
||||
|
||||
// SteamDB
|
||||
router.get('/steamdb/free/:type?', require('./routes/steam/steamdb/free'));
|
||||
|
||||
// 扇贝
|
||||
router.get('/shanbay/checkin/:id', require('./routes/shanbay/checkin'));
|
||||
router.get('/shanbay/footprints/:category?', require('./routes/shanbay/footprints'));
|
||||
|
||||
64
lib/routes/steam/steamdb/free.js
Normal file
64
lib/routes/steam/steamdb/free.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { type } = ctx.params;
|
||||
const url = 'https://steamdb.info/upcoming/free';
|
||||
const { data: html } = await got.get(url);
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const $trs = $('.container table.table-products:first-of-type tbody tr');
|
||||
const getItems = $trs
|
||||
.toArray()
|
||||
.reverse()
|
||||
.map(async (el) => {
|
||||
const $el = $(el);
|
||||
const $tds = $el.children('td');
|
||||
|
||||
// link & logo - 0
|
||||
const linkEl = $($tds.get(0)).find('a').get(0);
|
||||
const link = (linkEl && linkEl.attribs.href) || '';
|
||||
|
||||
// appid
|
||||
const found = /app\/(\d+)/.exec(link);
|
||||
const appid = found ? found[1] : '';
|
||||
|
||||
// title - 1
|
||||
const title = $($tds.get(1)).text().trim();
|
||||
|
||||
// promotion type - 2
|
||||
const promoType = $($tds.get(2)).text().trim();
|
||||
|
||||
// startDate - 3
|
||||
const startDate = $tds.get(3).attribs.title;
|
||||
|
||||
// endDate - 4
|
||||
// const endDate = $tds.get(4).attribs.title;
|
||||
|
||||
// ignore items without appid or not matched the type
|
||||
if (!appid || (type && type.toLowerCase() !== promoType.toLocaleLowerCase())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hoverLink = `https://steamdb.info/api/RenderAppHover/?appid=${appid}`;
|
||||
const description = await ctx.cache.tryGet(hoverLink, async () => {
|
||||
const { data: description } = await got.get(hoverLink);
|
||||
return description;
|
||||
});
|
||||
|
||||
return {
|
||||
title: `[${promoType}] ${title}`,
|
||||
link,
|
||||
pubDate: new Date(startDate).toUTCString(),
|
||||
description,
|
||||
};
|
||||
});
|
||||
|
||||
const item = await Promise.all(getItems);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Steam 免费游戏 [SteamDB]',
|
||||
link: url,
|
||||
item: item.filter((itm) => !!itm),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user