Fix: Detect charset of playlist instead of assuming UTF-8
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 18 Feb 2025 23:32:38 +0000 (00:32 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 18 Feb 2025 23:32:38 +0000 (00:32 +0100)
music_assistant/providers/filesystem_local/__init__.py

index 797a33d596f69616b4cf24183477c27078f4406b..c22889f63551bcaba6b0cb79b6f2c81da934ab27 100644 (file)
@@ -63,7 +63,12 @@ from music_assistant.helpers.ffmpeg import get_ffmpeg_stream
 from music_assistant.helpers.json import json_loads
 from music_assistant.helpers.playlists import parse_m3u, parse_pls
 from music_assistant.helpers.tags import AudioTags, async_parse_tags, parse_tags, split_items
-from music_assistant.helpers.util import TaskManager, parse_title_and_version, try_parse_int
+from music_assistant.helpers.util import (
+    TaskManager,
+    detect_charset,
+    parse_title_and_version,
+    try_parse_int,
+)
 from music_assistant.models.music_provider import MusicProvider
 
 from .constants import (
@@ -671,8 +676,11 @@ class LocalFileSystemProvider(MusicProvider):
         try:
             # get playlist file contents
             playlist_filename = self.get_absolute_path(prov_playlist_id)
-            async with aiofiles.open(playlist_filename, encoding="utf-8") as _file:
-                playlist_data = await _file.read()
+            async with aiofiles.open(playlist_filename, mode="rb") as _file:
+                playlist_data_raw = await _file.read()
+                encoding = await detect_charset(playlist_data_raw)
+                playlist_data = playlist_data_raw.decode(encoding, errors="replace")
+
             if ext in ("m3u", "m3u8"):
                 playlist_lines = parse_m3u(playlist_data)
             else: