feat(beatmap): support lookup api

This commit is contained in:
MingxuanGame
2025-07-27 09:01:33 +00:00
parent a8b05f1574
commit 19895789ac
3 changed files with 47 additions and 7 deletions

View File

@@ -8,11 +8,20 @@ from httpx import AsyncClient
class BeatmapFetcher(BaseFetcher):
async def get_beatmap(self, beatmap_id: int) -> BeatmapResp:
async def get_beatmap(
self, beatmap_id: int | None = None, beatmap_checksum: str | None = None
) -> BeatmapResp:
if beatmap_id:
params = {"id": beatmap_id}
elif beatmap_checksum:
params = {"checksum": beatmap_checksum}
else:
raise ValueError("Either beatmap_id or beatmap_checksum must be provided.")
async with AsyncClient() as client:
response = await client.get(
f"https://osu.ppy.sh/api/v2/beatmaps/{beatmap_id}",
"https://osu.ppy.sh/api/v2/beatmaps/lookup",
headers=self.header,
params=params,
)
response.raise_for_status()
return BeatmapResp.model_validate(response.json())