Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change scopes for replay downloading #256

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions aiosu/v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,16 +1819,15 @@ async def get_score_lazer(
@prepare_token
@check_token
@requires_scope(Scopes.PUBLIC)
@requires_scope(Scopes.IDENTIFY | Scopes.DELEGATE, any_scope=True)
async def get_score_replay(
self,
score_id: int,
legacy_score_id: int,
mode: Gamemode,
) -> BytesIO:
r"""Gets the replay file for a score.

:param score_id: The ID of the score
:type score_id: int
:param legacy_score_id: The ID of the score
:type legacy_score_id: int
:param mode: The gamemode to search for
:type mode: aiosu.models.gamemode.Gamemode

Expand All @@ -1837,7 +1836,27 @@ async def get_score_replay(
:return: Replay file
:rtype: io.BytesIO
"""
url = f"{self.base_url}/api/v2/scores/{mode}/{score_id}/download"
url = f"{self.base_url}/api/v2/scores/{mode}/{legacy_score_id}/download"
return await self._request("GET", url)

@prepare_token
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_score_replay_lazer(
self,
score_id: int,
) -> BytesIO:
r"""Gets the replay file for a score.

:param score_id: The ID of the score
:type score_id: int

:raises APIException: Contains status code and error message
:raises RefreshTokenExpiredError: If the client refresh token has expired
:return: Replay file
:rtype: io.BytesIO
"""
url = f"{self.base_url}/api/v2/scores/{score_id}/download"
return await self._request("GET", url)

@prepare_token
Expand Down
Binary file added tests/data/v2/get_score_replay_lazer_200.osr
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/v2/get_score_replay_lazer_404.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"error":"Specified Score\\Best\\Osu couldn't be found."}
11 changes: 11 additions & 0 deletions tests/generate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,17 @@ def _register_routes(self) -> None:
f"{DATA_DIR}/v2/get_score_replay_404.json",
expect_status=404,
)
self._register_route(
"GET",
f"{BASE_URL}/api/v2/scores/1581778626/download",
f"{DATA_DIR}/v2/get_score_replay_lazer_200.osr",
)
self._register_route(
"GET",
f"{BASE_URL}/api/v2/scores/0/download",
f"{DATA_DIR}/v2/get_score_replay_lazer_404.json",
expect_status=404,
)
self._register_route(
"GET",
f"{BASE_URL}/api/v2/rankings/osu/performance",
Expand Down
7 changes: 6 additions & 1 deletion tests/test_v2/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ async def test_generated(status_code, content_type, token, mocker):
generate_test(
aiosu.v2.Client.get_score_replay,
STATUS_CAN_404_OCTET,
func_kwargs={"score_id": 4220635589, "mode": "osu"},
func_kwargs={"legacy_score_id": 4220635589, "mode": "osu"},
),
generate_test(
aiosu.v2.Client.get_score_replay_lazer,
STATUS_CAN_404_OCTET,
func_kwargs={"score_id": 1581778626},
),
generate_test(
aiosu.v2.Client.get_rankings,
Expand Down