From ed5e7dc561a0931a76a5bdca6e155b51f08b6345 Mon Sep 17 00:00:00 2001 From: daydensteve Date: Wed, 25 Sep 2024 15:21:30 +0000 Subject: [PATCH] [chuni] Added truncation to long Title and Artist Name values on import (#178) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I noticed the importer failing to import music 523 (Niji-iro no Flügel) from an omni pack due to the artist name being crazy long. To address this, I added truncation to max column value length for both the Title and Artist Name values. Considered doing this for the other 3 string fields as well but I can't imagine those ever being problematic. Import now succeeds with a warning generated about the truncation occurring Reviewed-on: https://gitea.tendokyu.moe/Hay1tsme/artemis/pulls/178 Co-authored-by: daydensteve Co-committed-by: daydensteve --- titles/chuni/read.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/titles/chuni/read.py b/titles/chuni/read.py index 12b0d9e..eebdf8b 100644 --- a/titles/chuni/read.py +++ b/titles/chuni/read.py @@ -7,6 +7,7 @@ from PIL import Image from core.config import CoreConfig from titles.chuni.database import ChuniData from titles.chuni.const import ChuniConstants +from titles.chuni.schema.static import music as MusicTable class ChuniReader(BaseReader): @@ -144,6 +145,9 @@ class ChuniReader(BaseReader): self.logger.warning(f"Failed to insert event {id}") async def read_music(self, music_dir: str, we_diff: str = "4") -> None: + max_title_len = MusicTable.columns["title"].type.length + max_artist_len = MusicTable.columns["artist"].type.length + for root, dirs, files in walk(music_dir): for dir in dirs: if path.exists(f"{root}/{dir}/Music.xml"): @@ -154,9 +158,15 @@ class ChuniReader(BaseReader): for name in xml_root.findall("name"): song_id = name.find("id").text title = name.find("str").text + if len(title) > max_title_len: + self.logger.warning(f"Truncating music {song_id} song title") + title = title[:max_title_len] for artistName in xml_root.findall("artistName"): artist = artistName.find("str").text + if len(artist) > max_artist_len: + self.logger.warning(f"Truncating music {song_id} artist name") + artist = artist[:max_artist_len] for genreNames in xml_root.findall("genreNames"): for list_ in genreNames.findall("list"):