Skip to content

Read and write playlist files as UTF-8 - #834

Open
Alpenj wants to merge 1 commit into
Syncplay:masterfrom
Alpenj:fix-playlist-file-utf8
Open

Alpenj wants to merge 1 commit into
Syncplay:masterfrom
Alpenj:fix-playlist-file-utf8

Conversation

@Alpenj

@Alpenj Alpenj commented Nov 22, 2026

Copy link
Copy Markdown

SyncplayPlaylist.loadPlaylistFromFile() reads playlist files with the locale encoding. .m3u8 files are UTF-8 by definition, and the "Load playlist from file" dialog offers *.txt *.m3u8. On Windows the locale encoding is usually not UTF-8, so loading an .m3u8 playlist with non-ASCII file names raises UnicodeDecodeError (or, depending on the code page, loads garbled paths that cannot be found). If the file starts with a UTF-8 byte order mark, the BOM ends up in front of #EXTM3U, so that line is not skipped and becomes a playlist entry.

This PR:

  • reads playlist files as UTF-8 and drops a BOM if there is one,
  • falls back to the locale encoding if the file is not valid UTF-8, so .txt playlists saved by older versions of Syncplay still load,
  • saves playlists as UTF-8, so a saved playlist can be loaded on another computer.

Reproduction

Korean Windows (locale encoding cp949), an .m3u8 file saved as UTF-8:

#EXTM3U
#EXTINF:-1,제1화
D:\애니\제1화.mkv
D:\Łukasz ✨.mkv

Calling loadPlaylistFromFile() on it:

-- before
locale: cp949
error: UnicodeDecodeError 'cp949' codec can't decode byte 0xec in position 20: illegal multibyte sequence
-- after
locale: cp949
playlist: ['D:\\애니\\제1화.mkv', 'D:\\Łukasz ✨.mkv']

Tests

The repository has no test suite, so I did not add a test file. I checked the change with a local pytest script that makes open() default to cp1252 for text mode (so it fails on any OS without the fix) and covers:

  • an .m3u8 file in UTF-8, and one with a BOM,
  • saving a playlist with non-ASCII names and loading it again,
  • loading an old .txt playlist written in the locale encoding (the fallback).

Before the fix: 3 failed, 1 passed (the old locale-encoded file). After the fix: 4 passed.

loadPlaylistFromFile() read playlist files with the locale encoding.
.m3u8 files are UTF-8 by definition, so on Windows loading an .m3u8
playlist with non-ASCII file names raised UnicodeDecodeError or loaded
garbled paths, and a UTF-8 byte order mark ended up in the first entry.

Read playlist files as UTF-8 (with or without a BOM) and save them as
UTF-8. Playlists saved by older versions in the locale encoding still
load through a fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant