From: Marcel van der Veldt Date: Thu, 17 Oct 2024 10:54:59 +0000 (+0200) Subject: small tweak to encoding detect X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=20cc3da09073ea209b6507f7357f2c768b692725;p=music-assistant-server.git small tweak to encoding detect --- diff --git a/music_assistant/server/helpers/util.py b/music_assistant/server/helpers/util.py index 6cdde467..34ef1610 100644 --- a/music_assistant/server/helpers/util.py +++ b/music_assistant/server/helpers/util.py @@ -185,9 +185,12 @@ async def close_async_generator(agen: AsyncGenerator[Any, None]) -> None: async def detect_charset(data: bytes, fallback="utf-8") -> str: """Detect charset of raw data.""" try: - return (await asyncio.to_thread(chardet.detect, data))["encoding"] - except (ImportError, AttributeError): - return fallback + detected = await asyncio.to_thread(chardet.detect, data) + if detected and detected["encoding"] and detected["confidence"] > 0.75: + return detected["encoding"] + except Exception as err: + LOGGER.debug("Failed to detect charset: %s", err) + return fallback class TaskManager: