parsers.py
: Improve error handling for BPM/OFFSET parsing
This commit is contained in:
parent
6b93305d8b
commit
7b7dd15a62
@ -69,14 +69,21 @@ def split_tja_lines_into_courses(lines: List[str]) -> TJASong:
|
|||||||
if line.split("//")[0].strip()]
|
if line.split("//")[0].strip()]
|
||||||
|
|
||||||
# Initialize song with BPM and OFFSET global metadata
|
# Initialize song with BPM and OFFSET global metadata
|
||||||
bpm = float([line.split(":")[1] for line in lines
|
tja_metadata = {}
|
||||||
if line.startswith("BPM")][0])
|
for required_metadata in ["BPM", "OFFSET"]:
|
||||||
offset = float([line.split(":")[1] for line in lines
|
for line in lines:
|
||||||
if line.startswith("OFFSET")][0])
|
if line.startswith(required_metadata):
|
||||||
|
tja_metadata[required_metadata] = float(line.split(":")[1])
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise ValueError(f"TJA does not contain required "
|
||||||
|
f"'{required_metadata}' metadata.")
|
||||||
parsed_tja = TJASong(
|
parsed_tja = TJASong(
|
||||||
bpm=bpm,
|
bpm=tja_metadata['BPM'],
|
||||||
offset=offset,
|
offset=tja_metadata['OFFSET'],
|
||||||
courses={course: TJACourse(bpm=bpm, offset=offset, course=course)
|
courses={course: TJACourse(bpm=tja_metadata['BPM'],
|
||||||
|
offset=tja_metadata['OFFSET'],
|
||||||
|
course=course)
|
||||||
for course in TJA_COURSE_NAMES}
|
for course in TJA_COURSE_NAMES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user