forked from RealistikOsu/USSR
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Refactor osu!direct handlers #81
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e78d84b
add cheesegull abstractions
tsunyoku a1335eb
refactor osu! direct handlers to use cheesegull abstractions
tsunyoku bf5e77e
update example direct URL
tsunyoku 169d27f
whitespace
tsunyoku 327effb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import datetime | ||
|
||
from pydantic import BaseModel | ||
from pydantic import Field | ||
|
||
|
||
class CheesegullBeatmap(BaseModel): | ||
id: int = Field(..., alias="BeatmapID") | ||
beatmapset_id: int = Field(..., alias="ParentSetID") | ||
version: str = Field(..., alias="DiffName") | ||
checksum: str = Field(..., alias="FileMD5") | ||
mode: int = Field(..., alias="Mode") | ||
bpm: float = Field(..., alias="BPM") | ||
approach_rate: float = Field(..., alias="AR") | ||
overall_difficulty: float = Field(..., alias="OD") | ||
circle_size: float = Field(..., alias="CS") | ||
health_points: float = Field(..., alias="HP") | ||
total_length: int = Field(..., alias="TotalLength") | ||
hit_length: int = Field(..., alias="HitLength") | ||
play_count: int = Field(..., alias="Playcount") | ||
pass_count: int = Field(..., alias="Passcount") | ||
max_combo: int = Field(..., alias="MaxCombo") | ||
difficulty_rating: float = Field(..., alias="DifficultyRating") | ||
|
||
|
||
class CheesegullBeatmapset(BaseModel): | ||
id: int = Field(..., alias="SetID") | ||
beatmaps: list[CheesegullBeatmap] = Field(..., alias="ChildrenBeatmaps") | ||
ranked_status: int = Field(..., alias="RankedStatus") | ||
approved_date: datetime = Field(..., alias="ApprovedDate") | ||
last_update: datetime = Field(..., alias="LastUpdate") | ||
last_checked: datetime = Field(..., alias="LastChecked") | ||
artist: str = Field(..., alias="Artist") | ||
title: str = Field(..., alias="Title") | ||
creator: str = Field(..., alias="Creator") | ||
source: str = Field(..., alias="Source") | ||
tags: str = Field(..., alias="Tags") | ||
has_video: bool = Field(..., alias="HasVideo") | ||
genre: int | None = Field(None, alias="Genre") | ||
language: int | None = Field(None, alias="Language") | ||
favourites: int = Field(..., alias="Favourites") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
from app.models.cheesegull import CheesegullBeatmap | ||
from app.models.cheesegull import CheesegullBeatmapset | ||
|
||
|
||
def format_beatmapset_to_direct(beatmapset: CheesegullBeatmapset) -> str: | ||
# TODO: replace some of the placeholder values | ||
|
||
difficulty_sorted_beatmapsets = sorted( | ||
beatmapset.beatmaps, | ||
key=lambda x: x.difficulty_rating, | ||
) | ||
formatted_beatmaps = ",".join( | ||
format_beatmap_to_direct(beatmap) for beatmap in difficulty_sorted_beatmapsets | ||
) | ||
|
||
return ( | ||
f"{beatmapset.id}.osz|{beatmapset.artist}|{beatmapset.title}|{beatmapset.creator}|" | ||
f"{beatmapset.ranked_status}|10.0|{beatmapset.last_update}|{beatmapset.id}|" | ||
f"0|{beatmapset.has_video}|0|0|0|{formatted_beatmaps}" | ||
) | ||
|
||
|
||
def format_beatmap_to_direct(beatmap: CheesegullBeatmap) -> str: | ||
return ( | ||
f"[{beatmap.difficulty_rating:.2f}⭐] {beatmap.version} " | ||
f"{{cs: {beatmap.circle_size} / od: {beatmap.overall_difficulty} / ar: {beatmap.approach_rate} / hp: {beatmap.health_points}}}@{beatmap.mode}" | ||
) | ||
|
||
|
||
def format_beatmapset_to_direct_card(beatmapset: CheesegullBeatmapset) -> str: | ||
# TODO: replace some of the placeholder values | ||
|
||
return ( | ||
f"{beatmapset.id}.osz|{beatmapset.artist}|{beatmapset.title}|{beatmapset.creator}|" | ||
f"{beatmapset.ranked_status}|10.0|{beatmapset.last_update}|{beatmapset.id}|" | ||
"0|0|0|0|0" | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one gave me anxiety because any direct URL that has more than a single path prefix (
/
) would literally not work