Newer
Older
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
import logging
import uuid
from pathlib import Path
class UltraStarSongFile:
def __init__(self):
# Baisc Information
self.path = ""
self.title = ""
self.artist = ""
# TXT Metadata
self.creator = ""
self.version = ""
self.encoding = ""
# Detailed Song Information
self.edition = ""
self.genre = ""
self.language = ""
self.album = ""
self.year = ""
# Files used by Song
self.cover = ""
self.mp3 = ""
self.background = ""
self.video = ""
# Technical Information about Song
self.bpm = ""
self.length = ""
self.end = ""
self.gap = ""
self.videogap = ""
self.previewstart = ""
# Misc Shit
self.resolution = ""
self.id = ""
# Other
self.start = ""
self.notesgap = ""
self.relative = ""
self.medleystartbeat = ""
self.medleyendbeat = ""
self.calcmedley = ""
self.p1 = ""
self.p2 = ""
# Database Information
self.songid = ""
self.artistid = ""
self.albumid = ""
# Custom Tags
self.duet = False
self.custom_tags = []
# Songdata
self.songdata = [] # list of lines with songdata
def __eq__(self, other):
if isinstance(other, self.__class__):
if self.songid == "" or other.songid == "":
return (self.title == other.title) and (
self.artist == other.artist) and (self.duet == other.duet)
else:
return self.songid == other.songid
def set_attributes(self, parsed_data: dict) -> None:
"""
Setzt die attribute der Klasse
Args:
parsed_data: dict mit den geparseden tags und einem key "songdata"
der eine liste, mit den Text/Tonhöhe Zeilen enthält
"""
k: str
v: str
for k, v in parsed_data.items():
if hasattr(self, k.lower()):
setattr(self, k.lower(), v)
else:
self.custom_tags.append({k, v})
logging.debug("got custom tag: %s", k)
if self.songid == "":
self.songid = str(uuid.uuid4())
def dumps(self) -> str:
out: str = ""
out += f"#TITLE:{self.title}\n"
out += f"#ARTIST:{self.artist}\n"
out += f"#MP3:{self.mp3}\n"
out += f"#BPM:{self.bpm}\n"
out += f"#GAP:{self.gap}\n"
if self.creator:
out += f"#CREATOR:{self.creator}\n"
if self.version:
out += f"#VERSION:{self.version}\n"
if self.encoding:
out += f"#ENCODING:{self.encoding}\n"
if self.edition:
out += f"#EDITION:{self.edition}\n"
if self.genre:
out += f"#GENRE:{self.genre}\n"
if self.language:
out += f"#LANGUAGE:{self.language}\n"
if self.album:
out += f"#ALBUM:{self.album}\n"
if self.year:
out += f"#YEAR:{self.year}\n"
if self.cover:
out += f"#COVER:{self.cover}\n"
if self.background:
out += f"#BACKGROUND:{self.background}\n"
if self.video:
out += f"#VIDEO:{self.video}\n"
if self.length:
out += f"#LENGTH:{self.length}\n"
if self.end:
out += f"#END:{self.end}\n"
if self.videogap:
out += f"#VIDEOGAP:{self.videogap}\n"
if self.previewstart:
out += f"#PREVIEWSTART:{self.previewstart}\n"
if self.resolution:
out += f"#RESOLUTION:{self.resolution}\n"
if self.id:
out += f"#ID:{self.id}\n"
if self.start:
out += f"#START:{self.start}\n"
if self.notesgap:
out += f"#NOTESGAP:{self.notesgap}"
if self.relative:
out += f"#RELATIVE:{self.relative}\n"
if self.medleystartbeat:
out += f"#MEDLEYSTARTBEAT:{self.medleystartbeat}\n"
if self.medleyendbeat:
out += f"#MEDLEYENDBEAT:{self.medleyendbeat}\n"
if self.calcmedley:
out += f"#CALCMEDLEY:{self.calcmedley}\n"
if self.p1:
out += f"#P1:{self.p1}\n"
if self.p2:
out += f"#P2:{self.p2}\n"
if self.songid:
out += f"#SONGID:{self.songid}\n"
if self.artistid:
out += f"#ARTISTID:{self.artistid}\n"
if self.albumid:
out += f"#ALBUMID:{self.albumid}\n"
if self.duet:
out += f"#DUET:{self.duet}\n"
out += "".join(self.songdata)
return out
def dump(self, file: Path):
with open(file, "w", newline="\r\n") as f:
f.write(self.dumps())