feat(score): allow to recalculate all score pp

This commit is contained in:
MingxuanGame
2025-08-14 06:50:17 +00:00
parent c8b6c1fa0e
commit ebbc0b8252
5 changed files with 163 additions and 11 deletions

View File

@@ -2,10 +2,10 @@ from __future__ import annotations
from .beatmap import BeatmapFetcher
from .beatmapset import BeatmapsetFetcher
from .osu_dot_direct import OsuDotDirectFetcher
from .osu_dot_direct import BeatmapRawFetcher
class Fetcher(BeatmapFetcher, BeatmapsetFetcher, OsuDotDirectFetcher):
class Fetcher(BeatmapFetcher, BeatmapsetFetcher, BeatmapRawFetcher):
"""A class that combines all fetchers for easy access."""
pass

View File

@@ -3,21 +3,38 @@ from __future__ import annotations
from ._base import BaseFetcher
from httpx import AsyncClient
from httpx._models import Response
from loguru import logger
import redis.asyncio as redis
urls = [
"https://osu.ppy.sh/osu/{beatmap_id}",
"https://osu.direct/api/osu/{beatmap_id}",
"https://catboy.best/osu/{beatmap_id}",
]
class OsuDotDirectFetcher(BaseFetcher):
class BeatmapRawFetcher(BaseFetcher):
async def get_beatmap_raw(self, beatmap_id: int) -> str:
logger.opt(colors=True).debug(
f"<blue>[OsuDotDirectFetcher]</blue> get_beatmap_raw: <y>{beatmap_id}</y>"
)
for url in urls:
req_url = url.format(beatmap_id=beatmap_id)
logger.opt(colors=True).debug(
f"<blue>[BeatmapRawFetcher]</blue> get_beatmap_raw: <y>{req_url}</y>"
)
resp = await self._request(req_url)
if resp.status_code == 429:
continue
elif resp.status_code < 400:
return resp.text
else:
resp.raise_for_status()
async def _request(self, url: str) -> Response:
async with AsyncClient() as client:
response = await client.get(
f"https://osu.direct/api/osu/{beatmap_id}/raw",
url,
)
response.raise_for_status()
return response.text
return response
async def get_or_fetch_beatmap_raw(
self, redis: redis.Redis, beatmap_id: int