feat(beatmap): implement get beatmap arrtibutes
This commit is contained in:
@@ -2,9 +2,10 @@ from __future__ import annotations
|
||||
|
||||
from .beatmap import BeatmapFetcher
|
||||
from .beatmapset import BeatmapsetFetcher
|
||||
from .osu_dot_direct import OsuDotDirectFetcher
|
||||
|
||||
|
||||
class Fetcher(BeatmapFetcher, BeatmapsetFetcher):
|
||||
class Fetcher(BeatmapFetcher, BeatmapsetFetcher, OsuDotDirectFetcher):
|
||||
"""A class that combines all fetchers for easy access."""
|
||||
|
||||
pass
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.database.beatmap import BeatmapResp
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ._base import BaseFetcher
|
||||
|
||||
from httpx import AsyncClient
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.database.beatmap import BeatmapResp
|
||||
|
||||
|
||||
class BeatmapFetcher(BaseFetcher):
|
||||
async def get_beatmap(self, beatmap_id: int) -> BeatmapResp:
|
||||
async def get_beatmap(self, beatmap_id: int) -> "BeatmapResp":
|
||||
from app.database.beatmap import BeatmapResp
|
||||
|
||||
async with AsyncClient() as client:
|
||||
response = await client.get(
|
||||
f"https://osu.ppy.sh/api/v2/beatmaps/{beatmap_id}",
|
||||
|
||||
15
app/fetcher/osu_dot_direct.py
Normal file
15
app/fetcher/osu_dot_direct.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from ._base import BaseFetcher
|
||||
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
class OsuDotDirectFetcher(BaseFetcher):
|
||||
async def get_beatmap_raw(self, beatmap_id: int) -> str:
|
||||
async with AsyncClient() as client:
|
||||
response = await client.get(
|
||||
f"https://osu.direct/api/osu/{beatmap_id}/raw",
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.text
|
||||
Reference in New Issue
Block a user