From b20a50768b16a8df2e78f66e873e183c4217c5f0 Mon Sep 17 00:00:00 2001 From: Anthony Samms Date: Sun, 9 Nov 2025 14:44:28 -0500 Subject: [PATCH] getting very clever with encodings now --- dan_creator.py | 2 +- libs/file_navigator.py | 6 ++++++ libs/tja.py | 14 +++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/dan_creator.py b/dan_creator.py index dbafde9..4a6c98d 100644 --- a/dan_creator.py +++ b/dan_creator.py @@ -6,7 +6,7 @@ from pathlib import Path def create_dan(cache_path: Path): dan_data = {} dan_data["title"] = input("Enter the title: ") - dan_data["color"] = int(input("Enter the color: ")) + dan_data["color"] = int(input("Enter the color (0 10th Kyuu, 1 5th Kyuu, 2 Shodan, 3 6th Dan, 4 Kurouto, 5 Tatsujin, 6 Gaidan): ")) dan_data["exams"] = [] for i in range(3): exam = dict() diff --git a/libs/file_navigator.py b/libs/file_navigator.py index 7b26990..613ab9f 100644 --- a/libs/file_navigator.py +++ b/libs/file_navigator.py @@ -791,6 +791,7 @@ def parse_box_def(path: Path): """Parse box.def file for directory metadata""" texture_index = SongBox.DEFAULT_INDEX name = path.name + genre = '' collection = None encoding = test_encodings(path / "box.def") @@ -810,6 +811,11 @@ def parse_box_def(path: Path): name = line.split(":", 1)[1].strip() elif line.startswith("#COLLECTION"): collection = line.split(":", 1)[1].strip() + if name == '': + if genre: + name = genre + else: + name = path.name except Exception as e: logger.error(f"Error parsing box.def in {path}: {e}") diff --git a/libs/tja.py b/libs/tja.py index 36b6689..9ebaee7 100644 --- a/libs/tja.py +++ b/libs/tja.py @@ -265,7 +265,7 @@ def calculate_base_score(notes: NoteList) -> int: return 1000000 return math.ceil((1000000 - (balloon_count * 100) - (16.920079999994086 * drumroll_msec / 1000 * 100)) / total_notes / 10) * 10 -def test_encodings(file_path): +def test_encodings(file_path: Path): """Test the encoding of a file by trying different encodings. Args: @@ -274,7 +274,7 @@ def test_encodings(file_path): Returns: str: The encoding that successfully decoded the file. """ - encodings = ['utf-8-sig', 'shift-jis', 'utf-8'] + encodings = ['utf-8-sig', 'shift-jis', 'utf-8', 'utf-16', 'mac_roman'] final_encoding = None for encoding in encodings: @@ -427,19 +427,19 @@ class TJAParser: if balloon_data == '': logger.debug(f"Invalid BALLOONNOR value: {balloon_data} in TJA file {self.file_path}") continue - self.metadata.course_data[current_diff].balloon.extend([int(x) for x in balloon_data.split(',') if x != '']) + self.metadata.course_data[current_diff].balloon.extend([int(x) for x in balloon_data.replace('.', ',').split(',') if x != '']) elif item.startswith('BALLOONEXP'): balloon_data = item.split(':')[1] if balloon_data == '': logger.debug(f"Invalid BALLOONEXP value: {balloon_data} in TJA file {self.file_path}") continue - self.metadata.course_data[current_diff].balloon.extend([int(x) for x in balloon_data.split(',') if x != '']) + self.metadata.course_data[current_diff].balloon.extend([int(x) for x in balloon_data.replace('.', ',').split(',') if x != '']) elif item.startswith('BALLOONMAS'): balloon_data = item.split(':')[1] if balloon_data == '': logger.debug(f"Invalid BALLOONMAS value: {balloon_data} in TJA file {self.file_path}") continue - self.metadata.course_data[current_diff].balloon = [int(x) for x in balloon_data.split(',') if x != ''] + self.metadata.course_data[current_diff].balloon = [int(x) for x in balloon_data.replace('.', ',').split(',') if x != ''] elif item.startswith('BALLOON'): if item.find(':') == -1: self.metadata.course_data[current_diff].balloon = [] @@ -447,13 +447,13 @@ class TJAParser: balloon_data = item.split(':')[1] if balloon_data == '': continue - self.metadata.course_data[current_diff].balloon = [int(x) for x in balloon_data.split(',') if x != ''] + self.metadata.course_data[current_diff].balloon = [int(x) for x in balloon_data.replace('.', ',').split(',') if x != ''] elif item.startswith('SCOREINIT'): score_init = item.split(':')[1] if score_init == '': continue try: - self.metadata.course_data[current_diff].scoreinit = [int(x) for x in score_init.split(',') if x != ''] + self.metadata.course_data[current_diff].scoreinit = [int(x) for x in score_init.replace('.', ',').split(',') if x != ''] except Exception as e: logger.error(f"Failed to parse SCOREINIT: {e} in TJA file {self.file_path}") self.metadata.course_data[current_diff].scoreinit = [0, 0]