From 310bdb82dbb967af034114bd6ebb21f8a1f933d8 Mon Sep 17 00:00:00 2001 From: JimenezLi <75196426+JimenezLi@users.noreply.github.com> Date: Sat, 23 Sep 2023 13:23:34 +0800 Subject: [PATCH] feat(route): add osu! (#13366) * feat(route): add osu! * Remove test code * Update lib/v2/osu/radar.js --------- --- lib/v2/osu/beatmaps/packs.js | 35 +++++++++++++++++++++++++++++++++++ lib/v2/osu/maintainer.js | 3 +++ lib/v2/osu/radar.js | 13 +++++++++++++ lib/v2/osu/router.js | 3 +++ website/docs/routes/game.md | 6 ++++++ 5 files changed, 60 insertions(+) create mode 100644 lib/v2/osu/beatmaps/packs.js create mode 100644 lib/v2/osu/maintainer.js create mode 100644 lib/v2/osu/radar.js create mode 100644 lib/v2/osu/router.js diff --git a/lib/v2/osu/beatmaps/packs.js b/lib/v2/osu/beatmaps/packs.js new file mode 100644 index 000000000..c0b9f9b4f --- /dev/null +++ b/lib/v2/osu/beatmaps/packs.js @@ -0,0 +1,35 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { type = 'standard' } = ctx.params; + + const link = `https://osu.ppy.sh/beatmaps/packs?type=${type}`; + + const response = await got.get(link); + const $ = cheerio.load(response.data); + const itemList = $('.beatmap-pack'); + + ctx.state.data = { + title: `osu! Beatmap Pack - ${type}`, + link, + item: itemList.toArray().map((element) => { + const item = $(element); + const title = item.find('.beatmap-pack__name').text().trim(); + const link = item.find('.beatmap-pack__header').attr('href'); + // Trying to get the description will return 429 (Too Many Requests). + const description = item.find('.beatmap-pack__body').html(); + const pubDate = parseDate(item.find('.beatmap-pack__date').text(), 'YYYY-MM-DD'); + const author = item.find('.beatmap-pack__author--bold').text().trim(); + + return { + title, + link, + description, + pubDate, + author, + }; + }), + }; +}; diff --git a/lib/v2/osu/maintainer.js b/lib/v2/osu/maintainer.js new file mode 100644 index 000000000..54ee09cff --- /dev/null +++ b/lib/v2/osu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/packs/:type?': ['JimenezLi'], +}; diff --git a/lib/v2/osu/radar.js b/lib/v2/osu/radar.js new file mode 100644 index 000000000..350d758f0 --- /dev/null +++ b/lib/v2/osu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'ppy.sh': { + _name: 'osu!', + osu: [ + { + title: 'Beatmap Pack', + docs: 'https://docs.rsshub.app/routes/game#osu-beatmap-packs', + source: '/beatmaps/packs', + target: (params, url) => `https://osu.ppy.sh/beatmaps/packs?type=${new URL(url).searchParams.get('type') ?? 'standard'}`, + }, + ], + }, +}; diff --git a/lib/v2/osu/router.js b/lib/v2/osu/router.js new file mode 100644 index 000000000..3b8e6e542 --- /dev/null +++ b/lib/v2/osu/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/packs/:type?', require('./beatmaps/packs')); +}; diff --git a/website/docs/routes/game.md b/website/docs/routes/game.md index 474736586..cd8d1bb7f 100644 --- a/website/docs/routes/game.md +++ b/website/docs/routes/game.md @@ -398,6 +398,12 @@ Sorting types, default to `date`: +## osu! {#osu} + +### Beatmap Packs {#osu-beatmap-packs} + + + ## PlayStation Store {#playstation-store} ### Game List(Hong Kong) {#playstation-store-game-list-hong-kong}