Fix files not being opened with utf-8 encoding

This commit is contained in:
csd4ni3l
2025-05-24 17:34:13 +02:00
parent 0b70696194
commit 31bcf82534
6 changed files with 11 additions and 11 deletions

View File

@@ -18,7 +18,7 @@ class AddMusic(arcade.gui.UIView):
self.loaded_sounds = loaded_sounds self.loaded_sounds = loaded_sounds
self.shuffle = shuffle self.shuffle = shuffle
with open("settings.json", "r") as file: with open("settings.json", "r", encoding="utf-8") as file:
self.settings_dict = json.load(file) self.settings_dict = json.load(file)
self.playlists = self.settings_dict.get("playlists", {}) self.playlists = self.settings_dict.get("playlists", {})
@@ -60,7 +60,7 @@ class AddMusic(arcade.gui.UIView):
self.playlists[playlist].append(os.path.expanduser(music_path)) self.playlists[playlist].append(os.path.expanduser(music_path))
self.settings_dict["playlists"] = self.playlists self.settings_dict["playlists"] = self.playlists
with open("settings.json", "w") as file: with open("settings.json", "w", encoding="utf-8") as file:
file.write(json.dumps(self.settings_dict)) file.write(json.dumps(self.settings_dict))
def main_exit(self): def main_exit(self):

View File

@@ -24,7 +24,7 @@ class Downloader(arcade.gui.UIView):
self.pypresence_client = pypresence_client self.pypresence_client = pypresence_client
self.pypresence_client.update(state="Downloading music", start=self.pypresence_client.start_time) self.pypresence_client.update(state="Downloading music", start=self.pypresence_client.start_time)
with open("settings.json", "r") as file: with open("settings.json", "r", encoding="utf-8") as file:
self.settings_dict = json.load(file) self.settings_dict = json.load(file)
self.tab_options = self.settings_dict.get("tab_options", ["~/Music", "~/Downloads"]) self.tab_options = self.settings_dict.get("tab_options", ["~/Music", "~/Downloads"])
@@ -88,7 +88,7 @@ class Downloader(arcade.gui.UIView):
return None return None
try: try:
with open("downloaded_music.mp3.info.json", "r") as file: with open("downloaded_music.mp3.info.json", "r", encoding="utf-8") as file:
info = json.load(file) info = json.load(file)
return info return info
except (json.JSONDecodeError, OSError): except (json.JSONDecodeError, OSError):

View File

@@ -18,7 +18,7 @@ class Main(arcade.gui.UIView):
super().__init__() super().__init__()
self.pypresence_client = pypresence_client self.pypresence_client = pypresence_client
with open("settings.json", "r") as file: with open("settings.json", "r", encoding="utf-8") as file:
self.settings_dict = json.load(file) self.settings_dict = json.load(file)
if self.settings_dict.get('discord_rpc', True): if self.settings_dict.get('discord_rpc', True):

View File

@@ -18,7 +18,7 @@ class NewTab(arcade.gui.UIView):
self.loaded_sounds = loaded_sounds self.loaded_sounds = loaded_sounds
self.shuffle = shuffle self.shuffle = shuffle
with open("settings.json", "r") as file: with open("settings.json", "r", encoding="utf-8") as file:
self.settings_dict = json.load(file) self.settings_dict = json.load(file)
self.tab_options = self.settings_dict.get("tab_options", ["~/Music", "~/Downloads"]) self.tab_options = self.settings_dict.get("tab_options", ["~/Music", "~/Downloads"])
@@ -69,7 +69,7 @@ class NewTab(arcade.gui.UIView):
self.playlists[self.new_tab_input.text] = [] self.playlists[self.new_tab_input.text] = []
self.settings_dict["playlists"] = self.playlists self.settings_dict["playlists"] = self.playlists
with open("settings.json", "w") as file: with open("settings.json", "w", encoding="utf-8") as file:
file.write(json.dumps(self.settings_dict)) file.write(json.dumps(self.settings_dict))
def main_exit(self): def main_exit(self):

View File

@@ -20,7 +20,7 @@ class Settings(arcade.gui.UIView):
self.loaded_sounds = loaded_sounds self.loaded_sounds = loaded_sounds
self.shuffle = shuffle self.shuffle = shuffle
with open("settings.json", "r") as file: with open("settings.json", "r", encoding="utf-8") as file:
self.settings_dict = json.load(file) self.settings_dict = json.load(file)
self.pypresence_client = pypresence_client self.pypresence_client = pypresence_client
@@ -213,7 +213,7 @@ class Settings(arcade.gui.UIView):
self.display_category(self.current_category) self.display_category(self.current_category)
with open("settings.json", "w") as file: with open("settings.json", "w", encoding="utf-8") as file:
file.write(json.dumps(self.settings_dict, indent=4)) file.write(json.dumps(self.settings_dict, indent=4))
def update(self, setting=None, button_state=None, setting_type="bool"): def update(self, setting=None, button_state=None, setting_type="bool"):
@@ -261,7 +261,7 @@ class Settings(arcade.gui.UIView):
self.key_layout.clear() self.key_layout.clear()
self.value_layout.clear() self.value_layout.clear()
with open('CREDITS', 'r') as file: with open('CREDITS', 'r', encoding="utf-8") as file:
text = file.read() text = file.read()
if self.window.width == 3840: if self.window.width == 3840:

2
run.py
View File

@@ -67,7 +67,7 @@ else:
"discord_rpc": True "discord_rpc": True
} }
with open("settings.json", "w") as file: with open("settings.json", "w", encoding="utf-8") as file:
file.write(json.dumps(settings)) file.write(json.dumps(settings))
window = ControllerWindow(width=resolution[0], height=resolution[1], title='Music Player', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style) window = ControllerWindow(width=resolution[0], height=resolution[1], title='Music Player', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style)