#api-wrapper #osu #api #wrapper #api-response

rosu-v2

osu! API v2 包装器

13 个版本 (8 个破坏性更新)

0.9.0 2024年7月10日
0.8.0 2023年6月27日
0.7.0 2022年12月25日
0.6.2 2022年10月28日
0.2.0 2021年6月17日

网页编程 中排名 236

每月下载量 21

MIT 许可证

375KB
9K SLoC

crates.io docs

临时备注

由于转向 lazer,osu!api 在数据结构方面的状态异常不稳定。因此,而不是定期发布新版本,将保持 rosu-v2/lazer 分支的最新状态。

要使用 rosu-v2,建议在您的 Cargo.toml 中添加以下内容

rosu-v2 = { git = "https://github.com/MaxOhn/rosu-v2", branch = "lazer" }

但请注意,目前可能会定期发生破坏性更改。

rosu-v2

rosu-v2 是 osu!api v2 的包装器。因此,它提供了一组额外的端点和数据,这些数据在 rosu 中提供,该包装器封装了 osu!api v1

然而,osu!的 api v2 仍然是一个非常早期的版本,并且文档也很少。因此,有些东西可能会因为 api 的更改或响应未被正确解析而出现问题。

如果事情没有按预期工作,请随时打开一个问题。

身份验证

与 api v1 不同,api v2 不需要用户 apiKey。相反,它需要客户端id和客户端密钥。

要获取这些,您必须在 此处 注册一个应用程序。除非您对通过 osu!账户登录API感兴趣,否则此处不需要回调URL,可以留空。

如果您为用户进行了OAuth过程,您可以在创建客户端时提供回调URL和接收到的代码,以便代表已认证的用户进行请求。

端点

以下端点目前受支持

  • beatmaps/lookup:包括其 beatmapset 的特定 beatmap
  • beatmaps:一次最多50个 beatmap,包括它们的 beatmapset
  • beatmaps/{map_id}/attributes:Beatmap的难度属性
  • beatmaps/{map_id}/scores:Beatmap的全局分数排行榜
  • beatmaps/{map_id}/scores/users/{user_id}[/all]:获取(所有)用户在Beatmap上的最高分。默认为得分最高的玩法,而非PP
  • beatmapsets/{mapset_id}:包括所有难度Beatmap的Beatmap集
  • beatmapsets/events:围绕Beatmap集的各种事件,如状态、类型、语言更新,kudosu转移,或新问题
  • beatmapsets/search:搜索Beatmap集;与osu!网站上的搜索相同
  • comments:最近的评论及其最多两层深度的回复
  • events:按创建时间排序的事件集合
  • forums/topics/{topic_id}:论坛主题及其帖子
  • matches:当前打开的多玩家大厅列表
  • matches/{match_id}:特定多玩家大厅的更详细数据,包括参与玩家和发生的事件
  • me[/{mode}]:有关认证用户[在指定模式]的详细信息(需要OAuth)
  • news:最近的新闻
  • rankings/{mode}/{ranking_type}:全球性能积分、排名分数、国家或特别关注的全球排行榜
  • users/{user_id}/{recent_activity}:用户最近的事件列表,如获得的奖牌、Beatmap上的排名、用户名更改、支持者状态更新、Beatmap集状态更新等
  • scores/{mode}/{score_id}:包括其Beatmap、Beatmap集和用户的特定分数
  • seasonal-backgrounds:季节性背景列表,即它们的URL和艺术家
  • spotlights:所有特别关注的概述列表
  • users/{user_id}[/{mode}]:在指定模式下关于用户的详细信息
  • users/{user_id}/{beatmapsets/{map_type}:用户创建、收藏或最常玩的游戏谱面列表
  • users/{user_id}/kudosu:用户的最近kudosu转账记录
  • users/{user_id}/scores/{score_type}:用户的最高分、最近得分、固定得分或全球排名#1得分
  • users:一次最多50个用户,包括所有模式的统计数据
  • wiki/{locale}[/{path}]:通用维基页面或指定路径下的特定主题

API本身还提供了一些尚未实现的端点,因为它们要么是利基的,要么缺少任何文档。

如果您在API页面上找到了想要使用但rosu-v2中缺失的端点,请随时提出问题。

用法

// For convenience sake, all types can be found in the prelude module
use rosu_v2::prelude::*;

#[tokio::main]
async fn main() {
    // Initialize the client
    let client_id: u64 = 123;
    let client_secret = String::from("my_secret");
    let osu = Osu::new(client_id, client_secret).await.unwrap();

    // Get peppy's top 10-15 scores in osu!standard.
    // Note that the username here can only be used because of the `cache` feature.
    // If you are fine with just providing user ids, consider disabling this feature.
    let scores: Vec<Score> = osu.user_scores("peppy")
        .mode(GameMode::Osu)
        .best() // top scores; alternatively .recent(), .pinned(), or .firsts()
        .offset(10)
        .limit(5)
        .await
        .unwrap();

    // Search non-nsfw loved mania maps matching the given query.
    // Note that the order of called methods doesn't matter for any endpoint.
    let search_result: BeatmapsetSearchResult = osu.beatmapset_search()
        .nsfw(false)
        .status(Some(RankStatus::Loved))
        .mode(GameMode::Mania)
        .query("blue army stars>3")
        .await
        .unwrap();

    // Get the french wiki page on the osu file format
    let wiki_page: WikiPage = osu.wiki("fr")
        .page("Client/File_formats/osu_%28file_format%29")
        .await
        .unwrap();
}

功能

标志 描述 依赖
默认值 启用cachemacros功能
缓存 缓存用户名和user_id对,以便在所有用户端点上使用用户名而不是仅使用user_id dashmap
重新导出rosu-modsmods!宏,以便轻松为给定模式创建mod 粘贴
序列化 为大多数类型实现serde::Serialize,允许手动序列化
度量 使用全局度量注册表存储每个端点的响应时间 度量
回放 启用Osu::replay方法来解析回放。注意,Osu::replay_raw在此功能之外也可用,但提供原始字节数据而不是解析后的回放 osu-db
local_oauth 启用OsuBuilder::with_local_authorization方法以执行完整的OAuth流程 tokio/net功能

依赖

~16–28MB
~534K SLoC