-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
128 lines (102 loc) · 3.19 KB
/
config.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
from enum import StrEnum
from pathlib import Path
from typing import Any, TypeAlias
from attrs import define, field
from PIL import ImageColor
# NOTE RGBColor is specifically an RGB 3-tuple (red, green, blue).
RGBColor: TypeAlias = tuple[int, int, int]
def to_rgbcolor(val: Any) -> RGBColor:
if isinstance(val, str):
return ImageColor.getrgb(val)[:3]
raise TypeError("color value not convertible to RGBColor")
def to_rgbcolor_or_none(val: Any) -> RGBColor | None:
if val is None or val == "":
return None
if isinstance(val, str):
return ImageColor.getrgb(val)[:3]
raise TypeError("color value not convertible to RGBColor or None")
class LyricClearMode(StrEnum):
PAGE = "page"
LINE_EAGER = "eager"
LINE_DELAYED = "delayed"
class TextAlign(StrEnum):
LEFT = "left"
CENTER = "center"
RIGHT = "right"
class TextPlacement(StrEnum):
TOP_LEFT = "top left"
TOP_MIDDLE = "top middle"
TOP_RIGHT = "top right"
MIDDLE_LEFT = "middle left"
MIDDLE = "middle"
MIDDLE_RIGHT = "middle right"
BOTTOM_LEFT = "bottom left"
BOTTOM_MIDDLE = "bottom middle"
BOTTOM_RIGHT = "bottom right"
class StrokeType(StrEnum):
CIRCLE = "circle"
SQUARE = "square"
OCTAGON = "octagon"
@define
class SettingsInstrumental:
sync: int
line_tile_height: int
wait: bool = True
text: str = "INSTRUMENTAL"
text_align: TextAlign = TextAlign.CENTER
text_placement: TextPlacement = TextPlacement.MIDDLE
fill: RGBColor = field(converter=to_rgbcolor, default="#bbb")
stroke: RGBColor | None = field(
converter=to_rgbcolor_or_none,
default=None,
)
background: RGBColor | None = field(
converter=to_rgbcolor_or_none,
default=None,
)
image: Path | None = None
transition: str | None = None
x: int = 0
y: int = 0
@define
class SettingsSinger:
active_fill: RGBColor = field(converter=to_rgbcolor, default="#33f")
active_stroke: RGBColor = field(converter=to_rgbcolor, default="#004")
inactive_fill: RGBColor = field(converter=to_rgbcolor, default="#ddf")
inactive_stroke: RGBColor = field(converter=to_rgbcolor, default="#009")
@define
class SettingsLyric:
sync: list[int]
text: str
line_tile_height: int
lines_per_page: int
singer: int = 1
row: int = 1
@define
class Settings:
title: str
artist: str
file: Path
font: Path
outname: str = "output"
clear_mode: LyricClearMode = LyricClearMode.LINE_DELAYED
sync_offset: int = 0
highlight_bandwidth: int = 1
draw_bandwidth: int = 1
background: RGBColor = field(converter=to_rgbcolor, default="black")
border: RGBColor | None = field(
converter=to_rgbcolor_or_none,
default="black",
)
font_size: int = 18
stroke_width: int = 0
stroke_type: StrokeType = StrokeType.OCTAGON
instrumentals: list[SettingsInstrumental] = field(factory=list)
singers: list[SettingsSinger] = field(factory=list)
lyrics: list[SettingsLyric] = field(factory=list)
__all__ = [
"RGBColor",
"LyricClearMode", "TextAlign", "TextPlacement", "StrokeType",
"SettingsInstrumental", "SettingsSinger", "SettingsLyric",
"Settings",
]