getting very clever with encodings now

This commit is contained in:
Anthony Samms
2025-11-09 14:44:28 -05:00
parent e226119665
commit b20a50768b
3 changed files with 14 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ from pathlib import Path
def create_dan(cache_path: Path): def create_dan(cache_path: Path):
dan_data = {} dan_data = {}
dan_data["title"] = input("Enter the title: ") 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"] = [] dan_data["exams"] = []
for i in range(3): for i in range(3):
exam = dict() exam = dict()

View File

@@ -791,6 +791,7 @@ def parse_box_def(path: Path):
"""Parse box.def file for directory metadata""" """Parse box.def file for directory metadata"""
texture_index = SongBox.DEFAULT_INDEX texture_index = SongBox.DEFAULT_INDEX
name = path.name name = path.name
genre = ''
collection = None collection = None
encoding = test_encodings(path / "box.def") encoding = test_encodings(path / "box.def")
@@ -810,6 +811,11 @@ def parse_box_def(path: Path):
name = line.split(":", 1)[1].strip() name = line.split(":", 1)[1].strip()
elif line.startswith("#COLLECTION"): elif line.startswith("#COLLECTION"):
collection = line.split(":", 1)[1].strip() collection = line.split(":", 1)[1].strip()
if name == '':
if genre:
name = genre
else:
name = path.name
except Exception as e: except Exception as e:
logger.error(f"Error parsing box.def in {path}: {e}") logger.error(f"Error parsing box.def in {path}: {e}")

View File

@@ -265,7 +265,7 @@ def calculate_base_score(notes: NoteList) -> int:
return 1000000 return 1000000
return math.ceil((1000000 - (balloon_count * 100) - (16.920079999994086 * drumroll_msec / 1000 * 100)) / total_notes / 10) * 10 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. """Test the encoding of a file by trying different encodings.
Args: Args:
@@ -274,7 +274,7 @@ def test_encodings(file_path):
Returns: Returns:
str: The encoding that successfully decoded the file. 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 final_encoding = None
for encoding in encodings: for encoding in encodings:
@@ -427,19 +427,19 @@ class TJAParser:
if balloon_data == '': if balloon_data == '':
logger.debug(f"Invalid BALLOONNOR value: {balloon_data} in TJA file {self.file_path}") logger.debug(f"Invalid BALLOONNOR value: {balloon_data} in TJA file {self.file_path}")
continue 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'): elif item.startswith('BALLOONEXP'):
balloon_data = item.split(':')[1] balloon_data = item.split(':')[1]
if balloon_data == '': if balloon_data == '':
logger.debug(f"Invalid BALLOONEXP value: {balloon_data} in TJA file {self.file_path}") logger.debug(f"Invalid BALLOONEXP value: {balloon_data} in TJA file {self.file_path}")
continue 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'): elif item.startswith('BALLOONMAS'):
balloon_data = item.split(':')[1] balloon_data = item.split(':')[1]
if balloon_data == '': if balloon_data == '':
logger.debug(f"Invalid BALLOONMAS value: {balloon_data} in TJA file {self.file_path}") logger.debug(f"Invalid BALLOONMAS value: {balloon_data} in TJA file {self.file_path}")
continue 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'): elif item.startswith('BALLOON'):
if item.find(':') == -1: if item.find(':') == -1:
self.metadata.course_data[current_diff].balloon = [] self.metadata.course_data[current_diff].balloon = []
@@ -447,13 +447,13 @@ class TJAParser:
balloon_data = item.split(':')[1] balloon_data = item.split(':')[1]
if balloon_data == '': if balloon_data == '':
continue 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'): elif item.startswith('SCOREINIT'):
score_init = item.split(':')[1] score_init = item.split(':')[1]
if score_init == '': if score_init == '':
continue continue
try: 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: except Exception as e:
logger.error(f"Failed to parse SCOREINIT: {e} in TJA file {self.file_path}") logger.error(f"Failed to parse SCOREINIT: {e} in TJA file {self.file_path}")
self.metadata.course_data[current_diff].scoreinit = [0, 0] self.metadata.course_data[current_diff].scoreinit = [0, 0]