From 4a5abc873269a561da9eef572c7e3562d55fdc57 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Fri, 27 Oct 2023 19:07:24 +0300 Subject: [PATCH] forced utf-8 enabled for playlist read/write (#298) --- usr/lib/hypnotix/common.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/usr/lib/hypnotix/common.py b/usr/lib/hypnotix/common.py index 3af6a3e..7f42101 100755 --- a/usr/lib/hypnotix/common.py +++ b/usr/lib/hypnotix/common.py @@ -184,7 +184,7 @@ def get_playlist(self, provider, refresh=False) -> bool: # source = response.content.decode("UTF-8") # except UnicodeDecodeError as e: # source = response.content.decode("latin1") - with open(provider.path, "w") as file: + with open(provider.path, "w", encoding="utf-8") as file: # Grab data by block_bytes for data in response.iter_content(block_bytes,decode_unicode=True): downloaded_bytes += block_bytes @@ -210,7 +210,7 @@ def get_playlist(self, provider, refresh=False) -> bool: def check_playlist(self, provider): legit = False if os.path.exists(provider.path): - with open(provider.path, "r") as file: + with open(provider.path, "r", encoding="utf-8", errors="ignore") as file: content = file.read() if "#EXTM3U" in content and "#EXTINF" in content: legit = True @@ -220,7 +220,7 @@ def check_playlist(self, provider): return legit def load_channels(self, provider): - with open(provider.path, "r") as file: + with open(provider.path, "r", encoding="utf-8", errors="ignore") as file: channel = None group = None groups = {} @@ -293,12 +293,12 @@ def load_channels(self, provider): def load_favorites(self): favorites = [] - with open(FAVORITES_PATH, 'r') as f: + with open(FAVORITES_PATH, 'r', encoding="utf-8", errors="ignore") as f: for line in f: favorites.append(line.strip()) return favorites def save_favorites(self, favorites): - with open(FAVORITES_PATH, "w") as f: + with open(FAVORITES_PATH, "w", encoding="utf-8") as f: for fav in favorites: f.write(f"{fav}\n")