From d2746b93c1206718b2c92698e08236530ba0c27e Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Fri, 20 Jun 2025 17:05:22 +0200 Subject: [PATCH] fix download text having whitespace, fix display mode None crashing, and removed files and folders crashing --- menus/downloader.py | 2 +- menus/file_manager.py | 8 +++++++- menus/main.py | 19 ++++++++++++++++++- menus/settings.py | 7 ++++--- run.py | 7 +++++-- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/menus/downloader.py b/menus/downloader.py index ae10ae5..555c39f 100644 --- a/menus/downloader.py +++ b/menus/downloader.py @@ -80,7 +80,7 @@ class Downloader(arcade.gui.UIView): process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) for line in process.stdout: - self.yt_dl_buffer = line + self.yt_dl_buffer = line.strip() process.wait() diff --git a/menus/file_manager.py b/menus/file_manager.py index b959093..eb534d2 100644 --- a/menus/file_manager.py +++ b/menus/file_manager.py @@ -61,7 +61,10 @@ class FileManager(arcade.gui.UIView): def get_content(self, directory): if not directory in self.content_cache or time.perf_counter() - self.content_cache[directory][-1] >= 30: - entries = os.listdir(directory) + try: + entries = os.listdir(directory) + except PermissionError: + return None filtered = [ entry for entry in entries @@ -116,6 +119,9 @@ class FileManager(arcade.gui.UIView): self.file_buttons[-1].on_click = lambda event, file=f"{self.current_directory}/{file}": self.submit(file) def change_directory(self, directory): + if directory.startswith("//"): # Fix / paths + directory = directory[1:] + self.current_directory = directory self.show_directory() diff --git a/menus/main.py b/menus/main.py index 5b5f881..2120d6f 100644 --- a/menus/main.py +++ b/menus/main.py @@ -83,7 +83,7 @@ class Main(arcade.gui.UIView): self.load_content() self.create_ui() - + def create_ui(self): self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1))) @@ -163,6 +163,9 @@ class Main(arcade.gui.UIView): self.no_music_label = self.anchor.add(arcade.gui.UILabel(text="No music files were found in this directory or playlist.", font_name="Roboto", font_size=24), anchor_x="center", anchor_y="center") self.no_music_label.visible = False + self.no_playlists_label = self.anchor.add(arcade.gui.UILabel(text="You have no playlists.", font_name="Roboto", font_size=24)) + self.no_playlists_label.visible = False + if self.current_mode == "files": self.show_content(os.path.expanduser(self.current_tab)) elif self.current_mode == "playlist": @@ -291,6 +294,8 @@ class Main(arcade.gui.UIView): n = 0 + self.no_playlists_label.visible = not self.playlist_content[tab] + if self.current_playlist: if not self.search_term == "": matches = process.extract(self.search_term, self.playlist_content[tab], limit=5, processor=lambda text: text.lower(), scorer=fuzz.partial_token_sort_ratio) @@ -347,6 +352,11 @@ class Main(arcade.gui.UIView): for tab in self.tab_options: expanded_tab = os.path.expanduser(tab) + + if not os.path.exists(expanded_tab) or not os.path.isdir(expanded_tab): + self.tab_options.remove(tab) + return + self.tab_content[expanded_tab] = [] for filename in os.listdir(expanded_tab): @@ -359,6 +369,10 @@ class Main(arcade.gui.UIView): for playlist, content in self.settings_dict.get("playlists", {}).items(): for file in content: + if not os.path.exists(file) or not os.path.isfile(file): + content.remove(file) # also removes reference from self.settings_dict["playlists"] + continue + if file not in self.thumbnails: self.thumbnails[file] = get_audio_thumbnail_texture(file, self.window.size) @@ -373,6 +387,9 @@ class Main(arcade.gui.UIView): self.tab_buttons[os.path.expanduser(tab)] = self.tab_box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=os.path.basename(os.path.normpath(os.path.expanduser(tab))), style=button_style, width=self.window.width / 10, height=self.window.height / 15)) self.tab_buttons[os.path.expanduser(tab)].on_click = lambda event, tab=os.path.expanduser(tab): self.show_content(os.path.expanduser(tab)) elif self.current_mode == "playlist": + if not self.playlist_content: + self.no_playlists_label.visible = True + for playlist in self.playlist_content: self.tab_buttons[playlist] = self.tab_box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=playlist, style=button_style, width=self.window.width / 10, height=self.window.height / 15)) self.tab_buttons[playlist].on_click = lambda event, playlist=playlist: self.show_content(playlist) diff --git a/menus/settings.py b/menus/settings.py index 8918907..ae96857 100644 --- a/menus/settings.py +++ b/menus/settings.py @@ -1,4 +1,3 @@ -from arcade.gui.widgets.buttons import UITextureButton import copy, pypresence, json import arcade, arcade.gui @@ -163,7 +162,10 @@ class Settings(arcade.gui.UIView): if self.settings_dict['vsync']: self.window.set_vsync(True) display_mode = self.window.display.get_default_screen().get_mode() - refresh_rate = display_mode.rate + if display_mode: + refresh_rate = display_mode.rate + else: + refresh_rate = 60 self.window.set_update_rate(1 / refresh_rate) self.window.set_draw_rate(1 / refresh_rate) @@ -218,7 +220,6 @@ class Settings(arcade.gui.UIView): file.write(json.dumps(self.settings_dict, indent=4)) def update(self, setting=None, button_state=None, setting_type="bool"): - setting_dict = settings[self.current_category][setting] config_key = settings[self.current_category][setting]["config_key"] if setting_type == "option": diff --git a/run.py b/run.py index 48f09cb..b2b0aca 100644 --- a/run.py +++ b/run.py @@ -11,7 +11,7 @@ import logging, datetime, json, sys, arcade arcade.ArcadeContext.atlas_size = (16384, 16384) -from utils.utils import get_closest_resolution, print_debug_info, on_exception, ErrorView +from utils.utils import get_closest_resolution, print_debug_info, on_exception from utils.constants import log_dir, menu_background_color from menus.main import Main from arcade.experimental.controller_window import ControllerWindow @@ -77,7 +77,10 @@ window = ControllerWindow(width=resolution[0], height=resolution[1], title='Musi if vsync: window.set_vsync(True) display_mode = window.display.get_default_screen().get_mode() - refresh_rate = display_mode.rate + if display_mode: + refresh_rate = display_mode.rate + else: + refresh_rate = 60 window.set_update_rate(1 / refresh_rate) window.set_draw_rate(1 / refresh_rate) elif not fps_limit == 0: