From 605b09fa381827b9d6a348237a7b7d0e5e9dadeb Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sun, 15 Sep 2024 01:55:38 +0200 Subject: [PATCH] Fix: Handle radio stations providing non utf-8 in streamtitle (#1664) --- music_assistant/server/helpers/audio.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/music_assistant/server/helpers/audio.py b/music_assistant/server/helpers/audio.py index 84f08adda..6c975b1fc 100644 --- a/music_assistant/server/helpers/audio.py +++ b/music_assistant/server/helpers/audio.py @@ -564,7 +564,12 @@ async def get_icy_radio_stream( stream_title = re.search(rb"StreamTitle='([^']*)';", meta_data) if not stream_title: continue - stream_title = stream_title.group(1).decode() + try: + # in 99% of the cases the stream title is utf-8 encoded + stream_title = stream_title.group(1).decode("utf-8") + except UnicodeDecodeError: + # fallback to iso-8859-1 + stream_title = stream_title.group(1).decode("iso-8859-1", errors="replace") cleaned_stream_title = clean_stream_title(stream_title) if cleaned_stream_title != streamdetails.stream_title: LOGGER.log(VERBOSE_LOG_LEVEL, "ICY Radio streamtitle original: %s", stream_title)