convert: playlist: Enforce utf-8 encoding on load()

and write().
This commit is contained in:
J0J0 T 2022-08-27 19:09:06 +02:00 committed by J0J0 Todos
parent 785ef1576c
commit da01be3d93

View file

@ -39,7 +39,7 @@ class M3UFile():
def load(self):
"""Reads the m3u file from disk and sets the object's attributes."""
with open(syspath(self.path), "r") as playlist_file:
with open(syspath(self.path), "r", encoding="utf-8") as playlist_file:
raw_contents = playlist_file.readlines()
self.extm3u = True if raw_contents[0] == "#EXTM3U\n" else False
for line in raw_contents[1:]:
@ -70,6 +70,6 @@ class M3UFile():
if not self.media_list:
raise EmptyPlaylistError
contents = header + self.media_list
with open(syspath(self.path), "w") as playlist_file:
with open(syspath(self.path), "w", encoding="utf-8") as playlist_file:
playlist_file.writelines('\n'.join(contents))
playlist_file.write('\n') # Final linefeed to prevent noeol file.