Fix: Handle radio stations providing non utf-8 in streamtitle (#1664)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 14 Sep 2024 23:55:38 +0000 (01:55 +0200)
committerGitHub <noreply@github.com>
Sat, 14 Sep 2024 23:55:38 +0000 (01:55 +0200)
music_assistant/server/helpers/audio.py

index 84f08adda9a306f7d697871e6b82720a2288621a..6c975b1fc7abead88b0fe3a7a5221cb4b6ed4930 100644 (file)
@@ -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)