1
0
mirror of synced 2024-11-24 05:30:11 +01:00

parsers.py: Improve error handling for BPM/OFFSET parsing

This commit is contained in:
Viv 2024-02-10 18:10:45 -05:00
parent 6b93305d8b
commit 7b7dd15a62

View File

@ -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}
) )