Skip to content

Commit

Permalink
Merge pull request #5 from osuAkatsuki/new-thumbnail-design
Browse files Browse the repository at this point in the history
New thumbnail design
  • Loading branch information
lenforiee authored Jun 14, 2024
2 parents 9cffbd6 + 26e4bc1 commit 92ace3d
Show file tree
Hide file tree
Showing 4 changed files with 436 additions and 302 deletions.
2 changes: 2 additions & 0 deletions app/repositories/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Score(TypedDict):
play_mode: int
accuracy: float
pp: float
rank: str


async def fetch_one(score_id: int, relax: int) -> Score | None:
Expand Down Expand Up @@ -77,6 +78,7 @@ async def fetch_one(score_id: int, relax: int) -> Score | None:
"play_mode": resp["score"]["play_mode"],
"accuracy": resp["score"]["accuracy"],
"pp": resp["score"]["pp"],
"rank": resp["score"]["rank"],
}

return cast(Score, rec)
12 changes: 6 additions & 6 deletions app/usecases/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ def apply_effects_normal_template(image_path: str) -> Image.Image:
"""Apply effects for normal score template."""

im = resize_image(image_path, (1920, 1080))
im1 = apply_new_brightness(im, (0, 0, 1920, 244), 0.63)
im2 = apply_gaussian_blur(im1, (0, 0, 1920, 244), 3)
im3 = apply_shading(im2, (0, 0, 0), 0.39)
im4 = apply_saturation(im3, (13, 13, 97), 0.20)
im5 = apply_new_brightness(im4, (0, 0, 1920, 0), 1.1)
# im1 = apply_new_brightness(im, (0, 0, 1920, 244), 0.63)
# im2 = apply_gaussian_blur(im1, (0, 0, 1920, 244), 3)
# im3 = apply_shading(im2, (0, 0, 0), 0.39)
# im4 = apply_saturation(im3, (13, 13, 97), 0.20)
# im5 = apply_new_brightness(im4, (0, 0, 1920, 0), 1.1)

return im5
return im


def apply_effects_knockout_template(image_path: str) -> Image.Image:
Expand Down
114 changes: 72 additions & 42 deletions app/usecases/scorewatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ async def generate_normal_metadata(
relax_text = "Autopilot"

mods = aiosu.models.mods.Mods(score_data["mods"])
mode_icon = osu.int_to_osu_name(score_data["play_mode"])
title_colour = get_title_colour(relax)

osu_file_path = await osu.download_osu_file(score_data["beatmap"]["beatmap_id"])
if not osu_file_path:
Expand All @@ -144,13 +142,11 @@ async def generate_normal_metadata(
beatmap_artist = beatmap.artist
beatmap_title = beatmap.title
beatmap_difficulty_name = beatmap.version
map_full_combo = typing.cast(int, beatmap.max_combo)
except Exception: # When this happens, it's probably a mania map.
beatmap = osu.parse_osu_file_manually(osu_file_path)
beatmap_artist = beatmap["artist"]
beatmap_title = beatmap["title"]
beatmap_difficulty_name = beatmap["version"]
map_full_combo = 0

if not os.path.exists(
os.path.join(
Expand Down Expand Up @@ -194,11 +190,24 @@ async def generate_normal_metadata(
if not username:
username = score_data["user"]["username"]

performance_data = await performance.fetch_one(
score_data["beatmap"]["beatmap_md5"],
score_data["beatmap"]["beatmap_id"],
score_data["play_mode"],
score_data["mods"],
score_data["max_combo"],
score_data["accuracy"],
score_data["count_miss"],
)

if not performance_data:
return "Couldn't find performance data for this score!"

with open(os.path.join("templates", "scorewatch_normal.html")) as f:
template = f.read()

template = template.replace(
r"<% bg-image %>",
r"<% beatmap.background_url %>",
(
"/bot-data" # mounted in docker; DON'T TOUCH
+ "/"
Expand All @@ -209,31 +218,65 @@ async def generate_normal_metadata(
+ f"{score_data['beatmap']['beatmap_id']}_normal.png"
),
)
template = template.replace(r"<% misc-colour %>", detail_colour) # type: ignore
template = template.replace(r"<% title-colour %>", title_colour)
template = template.replace(r"<% username %>", username)
template = template.replace(r"<% mode %>", mode_icon)
template = template.replace(r"<% country %>", score_data["user"]["country"])
template = template.replace(r"<% userid %>", str(score_data["user"]["id"]))
template = template.replace(r"<% artist %>", artist) # type: ignore
template = template.replace(r"<% title %>", title) # type: ignore
template = template.replace(r"<% map-diff %>", difficulty_name) # type: ignore
template = template.replace(r"<% mods %>", f"+{mods}")

if map_full_combo > 0:
template = template.replace(
r"<% combo %>",
f"{score_data['max_combo']}x/{map_full_combo}x",
)
else:
template = template.replace(
r"<% combo %>",
f"{score_data['score']:,} ({score_data['max_combo']}x)",
)
template = template.replace(r"<% user.id %>", str(score_data["user"]["id"]))
template = template.replace(
r"<% score.grade %>", score_data["rank"].lower().replace("h", ""),
)
template = template.replace(
r"<% score.rank_golden_html %>",
"rank-golden" if "H" in score_data["rank"] else "",
)
template = template.replace(
r"<% score.is_fc_html %>", "is-fc" if score_data["full_combo"] else "",
)
template = template.replace(r"<% user.username %>", username)
template = template.replace(
r"<% user.country_code %>", score_data["user"]["country"].lower(),
)
template = template.replace(r"<% score.pp %>", str(int(score_data["pp"])))
template = template.replace(
r"<% score.accuracy %>", f"{score_data['accuracy']:.2f}",
)

mods_html = []
modifiers = [relax_text]
for mod in mods:

if Mod.Nightcore in mods and mod is Mod.DoubleTime:
continue
if Mod.Perfect in mods and mod is Mod.SuddenDeath:
continue

if mod == Mod.TouchDevice:
modifiers.append("Touchscreen")
continue

template = template.replace(r"<% pp-val %>", str(int(score_data["pp"])))
template = template.replace(r"<% acc %>", f"{score_data['accuracy']:.2f}")
template = template.replace(r"<% misc-text %>", detail_text) # type: ignore
mods_html.append(f'<div class="mod hard">{mod.short_name}</div>')

for modifier in modifiers:
mods_html.append(f'<div class="mod modifier">{modifier}</div>')

template = template.replace(
r"<% score.mods_html %>", "\n ".join(mods_html),
)

template = template.replace(
r"<% score.grade_upper %>", score_data["rank"].replace("H", ""),
)
template = template.replace(r"<% beatmap.name %>", title)
template = template.replace(r"<% beatmap.artist %>", artist)
template = template.replace(r"<% beatmap.version %>", difficulty_name)
template = template.replace(
r"<% beatmap.difficulty %>", f"{performance_data['stars']:.2f}",
)

template = template.replace(
r"<% score.has_misses_html %>",
"has-misses" if score_data["count_miss"] > 0 else "",
)
template = template.replace(
r"<% score.miss_count %>", str(score_data["count_miss"]),
)

with open(
os.path.join(
Expand Down Expand Up @@ -284,19 +327,6 @@ async def generate_normal_metadata(
quality=100,
)

performance_data = await performance.fetch_one(
score_data["beatmap"]["beatmap_md5"],
score_data["beatmap"]["beatmap_id"],
score_data["play_mode"],
score_data["mods"],
score_data["max_combo"],
score_data["accuracy"],
score_data["count_miss"],
)

if not performance_data:
return "Couldn't find performance data for this score!"

song_name = f"{artist} - {title} [{difficulty_name}]"
title_detail_text = detail_text.replace("xMiss", "❌") # type: ignore

Expand Down
Loading

0 comments on commit 92ace3d

Please sign in to comment.