-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
executable file
·173 lines (147 loc) · 4.12 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"""
main.py - the start of everything
"""
from __future__ import annotations
__author__ = "xJunko"
__discord__ = "xjunko"
import argparse
import sys
from pathlib import Path
import app.utils
from app.gazo import Replay2Picture
from app.generation.common import CanvasStyle, vector
from app.version import Version
#
CURRENT_VERSION = Version.from_str("0.8.1")
def main(argv: list[str]) -> int:
"""Ensure program is okay to run"""
for early_task in [app.utils.ensure_directories, app.utils.ensure_default_assets]:
if ret_code := early_task():
return ret_code
""" command-line arguments """
parser = argparse.ArgumentParser(
description="An open-source osu! thumbnail generator for lazy circle clickers.",
)
# Info
parser.add_argument(
"-v",
"--version",
action="version",
version=f"osr2png v{CURRENT_VERSION}",
)
# Source
parser.add_argument(
"-r",
"--replay",
help="[Optional] The path of the .osr file",
)
parser.add_argument(
"-b",
"--beatmap",
help="[Optional] The path of the .osu file, if using a custom beatmap.",
)
# Where to save
parser.add_argument(
"-o",
"--output",
help="[Optional] Change generated image filename.",
)
# Image Gen
parser.add_argument(
"-m",
"--message",
help="[Optional] The extra text at the bottom",
type=str,
default="",
)
parser.add_argument(
"-s",
"--style",
help="Style of Image, [{}]".format(
" ".join([f"{n.value}: {n.name}" for n in CanvasStyle]),
),
type=int,
default=1,
)
parser.add_argument(
"-width",
"--width",
help="[Optional] The width of the image.",
type=int,
default=1920,
)
parser.add_argument(
"-height",
"--height",
help="[Optional] The width of the image.",
type=int,
default=1080,
)
parser.add_argument(
"-dim",
"--background-dim",
help="[Optional] The dim of beatmap background.",
type=float,
default=0.6,
)
parser.add_argument(
"-blur",
"--background-blur",
help="[Optional] The blur of beatmap background.",
type=float,
default=5,
)
parser.add_argument(
"-border",
"--background-border",
help="[Optional] The border of beatmap background's dim.",
type=float,
default=25,
)
# Misc options
parser.add_argument(
"-skip",
"--skip-update",
help="[Optional] Don't check for a new version on Github.",
action="store_true",
)
args = parser.parse_args()
if not args.replay and not args.beatmap:
parser.print_help()
parser.error(
"No argument passed, please give `.osr` or `.osu` file into the params.",
)
if args.replay:
# Check for update
if not args.skip_update:
try:
app.utils.ensure_up_to_date(CURRENT_VERSION)
except Exception as _:
print("[Version] Failed to reached github.")
replay_path: Path = Path(args.replay)
beatmap_path: Path | None = None
if args.beatmap:
beatmap_path = Path(args.beatmap)
replay = Replay2Picture.from_replay_file(
replay_path=Path(replay_path),
beatmap_file=beatmap_path,
)
else:
# Generate from beatmap file only, SS everything.
# TODO:
parser.error("Beatmap only ImageGen is not supported yet.")
replay = Replay2Picture()
# Common
replay.calculate()
replay.generate(
style=args.style,
resolution=vector.Vector2(x=args.width, y=args.height), # type: ignore
background_blur=args.background_blur,
background_dim=args.background_dim,
background_border=args.background_border,
message=args.message,
custom_filename=args.output,
)
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv))